Skip to content

Commit e0d5cfc

Browse files
authored
Fix command mode (#401)
1 parent 195f850 commit e0d5cfc

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/pathpicker/screen.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This source code is licensed under the MIT license found in the
44
# LICENSE file in the root directory of this source tree.
55
from abc import ABC, abstractmethod
6-
from typing import TYPE_CHECKING, Tuple, Union
6+
from typing import TYPE_CHECKING, Tuple
77

88
if TYPE_CHECKING:
99
import curses
@@ -39,7 +39,7 @@ def getch(self) -> int:
3939
pass
4040

4141
@abstractmethod
42-
def getstr(self, y_pos: int, x_pos: int, max_len: int) -> Union[str, bytes, int]:
42+
def getstr(self, y_pos: int, x_pos: int, max_len: int) -> str:
4343
pass
4444

4545

@@ -68,5 +68,10 @@ def delch(self, y_pos: int, x_pos: int) -> None:
6868
def getch(self) -> int:
6969
return self.screen.getch()
7070

71-
def getstr(self, y_pos: int, x_pos: int, max_len: int) -> Union[str, bytes, int]:
72-
return self.screen.getstr(y_pos, x_pos, max_len)
71+
def getstr(self, y_pos: int, x_pos: int, max_len: int) -> str:
72+
result = self.screen.getstr(y_pos, x_pos, max_len)
73+
if isinstance(result, str):
74+
return result
75+
if isinstance(result, int):
76+
return str(result)
77+
return result.decode("utf-8")

src/pathpicker/screen_control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ def show_and_get_command(self) -> str:
592592
self.curses_api.echo()
593593
max_x = int(round(max_x - 1))
594594

595-
return str(self.stdscr.getstr(begin_height + 3, 0, max_x))
595+
return self.stdscr.getstr(begin_height + 3, 0, max_x)
596596

597597
def begin_enter_command(self) -> None:
598598
self.stdscr.erase()

src/tests/lib/screen.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This source code is licensed under the MIT license found in the
44
# LICENSE file in the root directory of this source tree.
55
from copy import copy
6-
from typing import Dict, List, NewType, Optional, Tuple, Union
6+
from typing import Dict, List, NewType, Optional, Tuple
77

88
from pathpicker.char_code_mapping import CHAR_TO_CODE
99
from pathpicker.screen import ScreenBase
@@ -89,7 +89,7 @@ def delch(self, y_pos: int, x_pos: int) -> None:
8989
def getch(self) -> int:
9090
return CHAR_TO_CODE[self.char_inputs.pop(0)]
9191

92-
def getstr(self, _y: int, _x: int, _max_len: int) -> Union[str, bytes, int]:
92+
def getstr(self, _y: int, _x: int, _max_len: int) -> str:
9393
# TODO -- enable editing this
9494
return ""
9595

0 commit comments

Comments
 (0)