Skip to content

Commit

Permalink
Fix command mode (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
KapJI authored Mar 12, 2021
1 parent 195f850 commit e0d5cfc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
13 changes: 9 additions & 4 deletions src/pathpicker/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Tuple, Union
from typing import TYPE_CHECKING, Tuple

if TYPE_CHECKING:
import curses
Expand Down Expand Up @@ -39,7 +39,7 @@ def getch(self) -> int:
pass

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


Expand Down Expand Up @@ -68,5 +68,10 @@ def delch(self, y_pos: int, x_pos: int) -> None:
def getch(self) -> int:
return self.screen.getch()

def getstr(self, y_pos: int, x_pos: int, max_len: int) -> Union[str, bytes, int]:
return self.screen.getstr(y_pos, x_pos, max_len)
def getstr(self, y_pos: int, x_pos: int, max_len: int) -> str:
result = self.screen.getstr(y_pos, x_pos, max_len)
if isinstance(result, str):
return result
if isinstance(result, int):
return str(result)
return result.decode("utf-8")
2 changes: 1 addition & 1 deletion src/pathpicker/screen_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ def show_and_get_command(self) -> str:
self.curses_api.echo()
max_x = int(round(max_x - 1))

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

def begin_enter_command(self) -> None:
self.stdscr.erase()
Expand Down
4 changes: 2 additions & 2 deletions src/tests/lib/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from copy import copy
from typing import Dict, List, NewType, Optional, Tuple, Union
from typing import Dict, List, NewType, Optional, Tuple

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

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

Expand Down

0 comments on commit e0d5cfc

Please sign in to comment.