Skip to content

Commit

Permalink
implemented changes however function will not run
Browse files Browse the repository at this point in the history
  • Loading branch information
Cornelius-Figgle committed Apr 8, 2024
1 parent 04173d8 commit 51d01be
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 12 additions & 0 deletions example/position.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pick

title = "Please choose your favorite programming language: "
options = ["Java", "JavaScript", "Python", "PHP", "C++", "Erlang", "Haskell"]
option, index = pick.pick(
options,
title,
indicator="=>",
default_index=2,
position=pick.Position(1,4)
)
print(f"You choosed {option} at index {index}")
9 changes: 6 additions & 3 deletions src/pick/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import curses
from collections import namedtuple
from dataclasses import dataclass, field
from typing import Any, List, Optional, Sequence, Tuple, TypeVar, Union, Generic

Expand All @@ -22,6 +23,8 @@ class Option:
OPTION_T = TypeVar("OPTION_T", str, Option)
PICK_RETURN_T = Tuple[OPTION_T, int]

Position = namedtuple('Position', ['x', 'y'])


@dataclass
class Picker(Generic[OPTION_T]):
Expand All @@ -34,7 +37,7 @@ class Picker(Generic[OPTION_T]):
selected_indexes: List[int] = field(init=False, default_factory=list)
index: int = field(init=False, default=0)
screen: Optional["curses._CursesWindow"] = None
position: dict = field(default_factory={"y0": 1, "x0": 1})
position: Position = field(default_factory=Position(1, 1))

def __post_init__(self) -> None:
if len(self.options) == 0:
Expand Down Expand Up @@ -114,7 +117,7 @@ def get_lines(self) -> Tuple[List, int]:

def draw(self, screen: "curses._CursesWindow", position: dict) -> None:
"""draw the curses ui on the screen, handle scroll if needed"""
x, y = position["x0"], position["y0"] # start point
x, y = position[0], position[1] # start point

max_y, max_x = screen.getmaxyx()
max_rows = max_y - y # the max rows we can draw
Expand Down Expand Up @@ -188,7 +191,7 @@ def pick(
multiselect: bool = False,
min_selection_count: int = 0,
screen: Optional["curses._CursesWindow"] = None,
position: dict = {"y0": 1, "x0": 1}
position: Position = Position(1, 1)
):
picker: Picker = Picker(
options,
Expand Down

0 comments on commit 51d01be

Please sign in to comment.