add top margin (configurable
This commit is contained in:
		
							parent
							
								
									be59fec4c9
								
							
						
					
					
						commit
						2ecf3026c7
					
				
					 5 changed files with 25 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -6,6 +6,7 @@ from .components import (
 | 
			
		|||
    ReferenceText,
 | 
			
		||||
    StatsComponent,
 | 
			
		||||
    TextBox,
 | 
			
		||||
    TopMargin,
 | 
			
		||||
)
 | 
			
		||||
from .listener import Listener
 | 
			
		||||
from .buffer import UserBuffer, Buffer
 | 
			
		||||
| 
						 | 
				
			
			@ -24,6 +25,7 @@ def initialize(configmap, rbuffer):
 | 
			
		|||
    reference_buffer = Buffer(rbuffer)
 | 
			
		||||
    user_buffer = UserBuffer()
 | 
			
		||||
 | 
			
		||||
    top_margin = TopMargin(config)
 | 
			
		||||
    cursor_component = CursorComponent(config)
 | 
			
		||||
    text_box = TextBox(config, cursor_component)
 | 
			
		||||
    user_input = UserInput(config, text_box)
 | 
			
		||||
| 
						 | 
				
			
			@ -35,7 +37,14 @@ def initialize(configmap, rbuffer):
 | 
			
		|||
 | 
			
		||||
    interface = Interface(
 | 
			
		||||
        application,
 | 
			
		||||
        [user_input, reference_text, text_box, stats_component, cursor_component],
 | 
			
		||||
        [
 | 
			
		||||
            top_margin,
 | 
			
		||||
            user_input,
 | 
			
		||||
            reference_text,
 | 
			
		||||
            text_box,
 | 
			
		||||
            stats_component,
 | 
			
		||||
            cursor_component,
 | 
			
		||||
        ],
 | 
			
		||||
    )
 | 
			
		||||
    wrapper(interface)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -44,6 +44,18 @@ class StatsComponent(TextComponent):
 | 
			
		|||
            self.paint_text(screen, text, self.color)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TopMargin(Base):
 | 
			
		||||
    def __init__(self, config):
 | 
			
		||||
        super().__init__()
 | 
			
		||||
        self.height = config.get("top_margin_percentage") / 100
 | 
			
		||||
 | 
			
		||||
    def paint(self, screen, application):
 | 
			
		||||
        maxy, _ = screen.getmaxyx()
 | 
			
		||||
        lines = int(self.height * maxy)
 | 
			
		||||
        for line in range(lines):
 | 
			
		||||
            screen.addstr("\n")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TextBox(TextComponent):
 | 
			
		||||
    """
 | 
			
		||||
    Wraps lines of text elements writing to it nicely
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,6 +21,7 @@ class Config:
 | 
			
		|||
            "accuracy: {stats.accuracy:0.2f}%"
 | 
			
		||||
        ),
 | 
			
		||||
        "summary_datafile": "~/.cache/fasttyper/datafile.csv",
 | 
			
		||||
        "top_margin_percentage": 30,
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    def __init__(self, configmap):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
[bumpversion]
 | 
			
		||||
current_version = 1.1.0
 | 
			
		||||
current_version = 1.3.3
 | 
			
		||||
 | 
			
		||||
[wheel]
 | 
			
		||||
universal = 1
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										2
									
								
								setup.py
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								setup.py
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
 | 
			
		|||
 | 
			
		||||
setup(
 | 
			
		||||
    name="fasttyper",
 | 
			
		||||
    version="1.3.2",
 | 
			
		||||
    version="1.3.3",
 | 
			
		||||
    author="Piotr Domanski",
 | 
			
		||||
    author_email="pi.domanski@gmail.com",
 | 
			
		||||
    description="Minimalistic typing exercise",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue