Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion consolemenu/console_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self, title=None, subtitle=None, screen=None, formatter=None,
self.clear_screen_before_render = clear_screen

if formatter is None:
formatter = MenuFormatBuilder()
formatter = MenuFormatBuilder(max_dimension=(screen.screen_width, screen.screen_width))
self.formatter = formatter

self.title = title
Expand Down
4 changes: 4 additions & 0 deletions consolemenu/menu_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,11 @@ class MenuFooter(MenuComponent):
The menu footer contains the menu bottom, bottom padding verticals, and bottom margin.
"""

def SetHeight(self, height):
self.height = height

def generate(self):
self.padding.top += self.height
for x in range(0, self.padding.top):
yield self.row()
yield self.outer_horizontal_border_bottom()
Expand Down
14 changes: 13 additions & 1 deletion consolemenu/menu_formatter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from consolemenu.format.menu_borders import MenuBorderStyle, MenuBorderStyleFactory
from consolemenu.format.menu_style import MenuStyle
import os
from consolemenu.menu_component import Dimension, MenuHeader, MenuTextSection, MenuItemsSection, MenuFooter, MenuPrompt


Expand All @@ -11,6 +12,11 @@ class MenuFormatBuilder(object):
def __init__(self, max_dimension=None):
if max_dimension is None:
max_dimension = Dimension(width=80, height=40)
self.__height = 40
else:
size = os.get_terminal_size()
self.__height = size.lines
max_dimension = Dimension(width=max_dimension[0], height=max_dimension[1])
self.__max_dimension = max_dimension
self.__border_style_factory = MenuBorderStyleFactory()
self.__header = MenuHeader(menu_style=MenuStyle(), max_dimension=max_dimension)
Expand Down Expand Up @@ -281,7 +287,13 @@ def format(self, title=None, subtitle=None, prologue_text=None, epilogue_text=No
sections.append(self.__footer)
sections.append(self.__prompt)
for sect in sections:
content += "\n".join(sect.generate())
if isinstance(sect, MenuFooter):
rows = content.count('\n') + 3
empty = self.__height - rows
sect.SetHeight(empty)
content += "\n".join(sect.generate())
else:
content += "\n".join(sect.generate())
# Don't add newline to prompt so input is on same line as prompt
if not isinstance(sect, MenuPrompt):
content += "\n"
Expand Down
16 changes: 12 additions & 4 deletions consolemenu/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@
import platform
import subprocess
import sys

import os

class Screen(object):
"""
Class representing a console screen.
"""

def __init__(self):
# TODO get actual screen size
self.__height = 40
self.__width = 80
self.refresh()

def refresh(self):
try:
size = os.get_terminal_size()
self.__height = size.lines
self.__width = size.columns

except Exception:
self.__height = 40
self.__width = 80

@property
def screen_height(self):
Expand Down