Improved console

This commit is contained in:
Sven Heidemann 2020-12-15 16:53:15 +01:00
parent 7473b8deab
commit 78c4b6ef09
16 changed files with 47 additions and 38 deletions

View File

@ -8,8 +8,8 @@ from sh_edraft.configuration.model.configuration_variable_name import Configurat
from sh_edraft.environment.base.environment_base import EnvironmentBase
from sh_edraft.environment.hosting_environment import HostingEnvironment
from sh_edraft.environment.model.environment_name import EnvironmentName
from sh_edraft.utils.console.console import Console
from sh_edraft.utils.console.model.foreground_color import ForegroundColor
from sh_edraft.console.console import Console
from sh_edraft.console.model import ForegroundColor
class Configuration(ConfigurationBase):

View File

@ -1,12 +1,9 @@
import contextlib
import io
import os
import sys
from typing import Union, Optional
from termcolor import colored
from sh_edraft.utils.console.model.background_color import BackgroundColor
from sh_edraft.utils.console.model.foreground_color import ForegroundColor
from sh_edraft.console.model.background_color import BackgroundColor
from sh_edraft.console.model.foreground_color import ForegroundColor
class Console:
@ -93,17 +90,24 @@ class Console:
@staticmethod
def close():
Console.read_line('\nPress any key to continue...')
Console.reset()
Console.write('\n\n\nPress any key to continue...')
Console.read_line()
exit()
@staticmethod
def read(output: str = None) -> str:
user_input = input(output if output else '')
return user_input[0]
@classmethod
def read(cls, output: str = None) -> str:
if output is not None:
cls.write(output)
@staticmethod
def read_line(output: str = None) -> str:
return input(output if output else '')
return input()[0]
@classmethod
def read_line(cls, output: str = None) -> str:
if output is not None:
cls.write(output)
return input()
@classmethod
def reset(cls):
@ -118,14 +122,16 @@ class Console:
@classmethod
def write_at(cls, x: int, y: int, *args):
string = ' '.join(map(str, args))
cls._output(string, x, y)
cls._output(string, x, y, end='')
@classmethod
def write_line(cls, *args):
string = ' '.join(map(str, args))
cls._output(string)
cls._output('')
cls._output(string, end='')
@classmethod
def write_line_at(cls, x: int, y: int, *args):
string = ' '.join(map(str, args))
cls._output(string, x, y)
cls._output('', end='')
cls._output(string, x, y, end='')

View File

@ -5,8 +5,8 @@ from sqlalchemy.orm import Session, sessionmaker
from sh_edraft.database.connection.base.database_connection_base import DatabaseConnectionBase
from sh_edraft.database.model.database_settings import DatabaseSettings
from sh_edraft.utils.console.console import Console
from sh_edraft.utils.console.model.foreground_color import ForegroundColor
from sh_edraft.console.console import Console
from sh_edraft.console.model.foreground_color import ForegroundColor
class DatabaseConnection(DatabaseConnectionBase):

View File

@ -6,8 +6,8 @@ from sh_edraft.database.connection.base.database_connection_base import Database
from sh_edraft.database.context.base.database_context_base import DatabaseContextBase
from sh_edraft.database.model.dbmodel import DBModel
from sh_edraft.database.model.database_settings import DatabaseSettings
from sh_edraft.utils.console.console import Console
from sh_edraft.utils.console.model.foreground_color import ForegroundColor
from sh_edraft.console.console import Console
from sh_edraft.console.model.foreground_color import ForegroundColor
class DatabaseContext(DatabaseContextBase):

View File

@ -3,8 +3,8 @@ from typing import Optional
from sh_edraft.configuration.base.configuration_model_base import ConfigurationModelBase
from sh_edraft.database.model.database_settings_name import DatabaseSettingsName
from sh_edraft.utils.console.console import Console
from sh_edraft.utils.console.model.foreground_color import ForegroundColor
from sh_edraft.console.console import Console
from sh_edraft.console.model.foreground_color import ForegroundColor
class DatabaseSettings(ConfigurationModelBase):

View File

@ -8,7 +8,7 @@ from sh_edraft.hosting.application_runtime import ApplicationRuntime
from sh_edraft.hosting.base.application_host_base import ApplicationHostBase
from sh_edraft.service.providing.service_provider import ServiceProvider
from sh_edraft.service.providing.base.service_provider_base import ServiceProviderBase
from sh_edraft.utils.console import Console
from sh_edraft.console import Console
class ApplicationHost(ApplicationHostBase):

View File

@ -8,8 +8,8 @@ from sh_edraft.logging.base.logger_base import LoggerBase
from sh_edraft.logging.model.logging_settings import LoggingSettings
from sh_edraft.logging.model.logging_level import LoggingLevel
from sh_edraft.time.model.time_format_settings import TimeFormatSettings
from sh_edraft.utils.console.console import Console
from sh_edraft.utils.console.model.foreground_color import ForegroundColor
from sh_edraft.console.console import Console
from sh_edraft.console.model.foreground_color import ForegroundColor
class Logger(LoggerBase):

View File

@ -4,8 +4,8 @@ from typing import Optional
from sh_edraft.configuration.base.configuration_model_base import ConfigurationModelBase
from sh_edraft.logging.model.logging_settings_name import LoggingSettingsName
from sh_edraft.logging.model.logging_level import LoggingLevel
from sh_edraft.utils.console.console import Console
from sh_edraft.utils.console.model.foreground_color import ForegroundColor
from sh_edraft.console.console import Console
from sh_edraft.console.model.foreground_color import ForegroundColor
class LoggingSettings(ConfigurationModelBase):

View File

@ -4,8 +4,8 @@ from typing import Optional
from sh_edraft.configuration.base.configuration_model_base import ConfigurationModelBase
from sh_edraft.publishing.model.template import Template
from sh_edraft.publishing.model.publish_settings_name import PublishSettingsName
from sh_edraft.utils.console.console import Console
from sh_edraft.utils.console.model.foreground_color import ForegroundColor
from sh_edraft.console.console import Console
from sh_edraft.console.model.foreground_color import ForegroundColor
class PublishSettings(ConfigurationModelBase):

View File

@ -3,8 +3,8 @@ from typing import Optional
from sh_edraft.configuration.base.configuration_model_base import ConfigurationModelBase
from sh_edraft.time.model.time_format_settings_names import TimeFormatSettingsNames
from sh_edraft.utils.console.console import Console
from sh_edraft.utils.console.model.foreground_color import ForegroundColor
from sh_edraft.console.console import Console
from sh_edraft.console.model.foreground_color import ForegroundColor
class TimeFormatSettings(ConfigurationModelBase):

View File

@ -20,7 +20,6 @@ __version__ = '2020.12.5'
from collections import namedtuple
# imports:
from .console import Console
from .credential_manager import CredentialManager
VersionInfo = namedtuple('VersionInfo', 'major minor micro')

View File

@ -1,6 +1,7 @@
from typing import Optional
from sh_edraft.configuration.base import ConfigurationBase
from sh_edraft.console import Console
from sh_edraft.database.context import DatabaseContext
from sh_edraft.database.model import DatabaseSettings
from sh_edraft.hosting import ApplicationHost
@ -8,7 +9,7 @@ from sh_edraft.hosting.base import ApplicationBase
from sh_edraft.logging import Logger
from sh_edraft.logging.base import LoggerBase
from sh_edraft.service.providing.base import ServiceProviderBase
from sh_edraft.utils import CredentialManager, Console
from sh_edraft.utils import CredentialManager
from tests_dev.db.user_repo import UserRepo
from tests_dev.db.user_repo_base import UserRepoBase
@ -65,10 +66,13 @@ class Program(ApplicationBase):
Console.set_background_color('green')
Console.set_cursor_position(5, 5)
Console.write_line('Error')
Console.write_line_at(10, 10, 'Error')
Console.write_line_at(10, 5, 'Error')
Console.write_at(15, 5, 'Error')
Console.reset_cursor_position()
Console.set_foreground_color('green')
Console.set_background_color('default')
Console.write('Test')
Console.write_line('1')
Console.write_line('Test')
Console.write('1')
# Console.write('x: ')
# Console.read_line('Test> ')
Console.write_line(Console.foreground_color)