Skip to content

Commit 4b0be91

Browse files
committed
Call init_utils only once.
1 parent 76513f4 commit 4b0be91

3 files changed

Lines changed: 13 additions & 15 deletions

File tree

scrolltext/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def main():
2626
try:
2727
cfg = init_utils(write_config)
2828
action = action or _str_to_action_type(cfg["main"]["action"])
29-
action(write_config)
29+
action(cfg)
3030
except KeyError as e:
3131
print("KeyError occured: " + str(e) +
3232
"\nProbalby check config?")

scrolltext/cursestext.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from curses import wrapper, error
55
import curses
66
import logging
7-
from .utils import CharacterScroller, IS_WINDOWS, init_utils
7+
from .utils import CharacterScroller, IS_WINDOWS
88

99

1010
QUIT_CHARACTERS = ["\x1B", "Q", "q"]
@@ -13,19 +13,18 @@
1313
log = logging.getLogger(__name__)
1414

1515

16-
def curses_scroller(win, write_config):
16+
def curses_scroller(win, cfg):
1717
"""
1818
Curses-main: render a text in a side-scrolling manner, using curses.
1919
2020
:param win: Internal curses based object
2121
:type win: curses._window
22-
:param write_config: Write initial config
23-
:type: bool
22+
:param cfg: Config object
23+
:type: configerparser.ConfigParser
2424
"""
2525
winsize = win.getmaxyx()
2626
log.debug("win dimensions: (columns, rows) (%d, %d)", winsize[1], winsize[0])
2727

28-
cfg = init_utils(write_config)
2928
box = cfg["cursestext"].getboolean("box")
3029
# try:
3130
if box:
@@ -86,11 +85,11 @@ def check_quit(win):
8685
return False
8786

8887

89-
def work(write_config):
88+
def work(cfg):
9089
"""Main usese curses.wrapper. See curses doc for details.
9190
"""
9291
try: # noqa: C901 ignoring 'TryExcept 42' is too complex - fix later
93-
wrapper(curses_scroller, write_config)
92+
wrapper(curses_scroller, cfg)
9493
except error as ex:
9594
log.exception(ex)
9695
finally:

scrolltext/linescroller.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44
import shutil
55
from time import sleep
6-
from .utils import CLEAR, HOME, IS_WINDOWS, UP_ONE_ROW, CharacterScroller, init_utils
6+
from .utils import CLEAR, HOME, IS_WINDOWS, UP_ONE_ROW, CharacterScroller
77

88
if not IS_WINDOWS:
99
from scrolltext.getchtimeout import GetchWithTimeout
@@ -12,29 +12,28 @@
1212
VISIBILE_TEXT_LENGTH = shutil.get_terminal_size()[0]
1313

1414

15-
def linescroller(write_config):
15+
def linescroller(cfg):
1616
"""
1717
Main entry point for linescroller.
18-
:param write_config: Write initial config
19-
:type: bool
18+
:param cfg: Config object
19+
:type: configparser.ConfigParser
2020
"""
2121
getch = None
2222
if not IS_WINDOWS:
2323
getch = GetchWithTimeout()
2424
try:
25-
_linescroller(getch, write_config)
25+
_linescroller(getch, cfg)
2626
except RuntimeError:
2727
pass
2828
finally:
2929
if not IS_WINDOWS:
3030
getch.cleanup()
3131

3232

33-
def _linescroller(getch, write_config):
33+
def _linescroller(getch, cfg):
3434
"""
3535
Prints a text in a side-scrolling manner.
3636
"""
37-
cfg = init_utils(write_config)
3837
argv = {}
3938
argv["term_rows"] = shutil.get_terminal_size()[1]
4039
argv["term_columns"] = shutil.get_terminal_size()[0] - (1 if IS_WINDOWS else 0)

0 commit comments

Comments
 (0)