Package: terapp
TerCLI FrameworkTer is the CLI Framework that will build a CLI application with cool syntax which will amaze your school coding projects.In Ter, we are strongly amaze the syntax and terminologies of other modern UI framework. Our main purpose of creating this framework is to make the terminal app more interactive and fancy with pages, command prompt, and built-in UI.Main concept ofTerEverything that you can see on the terminal screen is the result ofprintstatement in Python. Then the screen is paused to wait for the user command byinputstatement. We consider everytime that printing out and waiting for input for future change is astate(inspired by React).Each state includes:clear screen -> render component -> pause program -> run logicThe state will continuously loop until theexitmethod is called.Clear screen phase: Create your terminal and ready to print new content.Render component phase: Render your content with new data. (State is changed)Pause programm phase: Pause program to listen input from user.Run logic phase: Execute logic based on user input to change the data.Quick startInstallterappin Python package.$pipinstallterappCreate a simpleTerapp# Import libsimportterapp# Create app instanceapp=terapp.Ter()# Define ScreenclassMyScreen(ter.Component):def__init__(self):self.count=0# Override render methoddefrender(self,context):print("Counting app")print(self.count)# Print count value# Override prompt methoddefprompt(self):return"Enter your number: "# Override logic methoddeflogic(self,command,context):# Add user number to countself.count+=int(command)# Add Screen to route. Ter will get the first route as init screenapp.register_routes({'home':MyScreen})# Begin loop of your appapp.run()Folder StructureTer is strongly recommending uses organize app's files. By using this structure, your app is more scalable and easy to maintain in the future.your_folder
    └ screens
    |    └ your_screen.py
    └ state
    |    └ your_state.py
    └ main.pyscreens folder contains all your screen of your app.state folder contains all global state of your app. (Inspired by Redux)main.py contains theappinstance and some config for your app.Ter AppTer manages every things in the app instance. Include all the screen in your app.fromterappimportTerapp=Ter()Ter provides the Config class which includes all the custom config of app. Ter config includes:default_pause_message(str): If you don't override thepromptmethod, this string will be displayed instead.fromterappimportTer,Configapp=Ter(config=Config(default_pause_message="Press enter to continue..."))# Or you can provide config by config methodapp.config(config=Config(default_pause_message="Press enter to continue..."))ComponentIn ter, we define every screen is a component which always have methods:render(required): This method will run first and do all code inside it before program will be pause.prompt(optional): This method must return a string for a user prompt message. If not, the prompt message will usedefault_pause_messageinstead.logic(optional): This method will run after the user complete typing the prompt to run your desired logic before the new loop.fromterappimportComponentclassYourScreen(Component):def__init__(self):# Define your local variable hereself.local_variable=...# Render methoddefrender(self,context):# Print something...# Prompt method, optionaldefprompt(self):return"Some message"# Logic method, optionaldeflogic(self,command,context):# Do somthing with use input at command params...To add your screen into app, register routes inmain.pyfile# Import YourScreen class from screens folderfromscreensimportYourScreen# The register_routes method requires a dictionary of Componentsapp.register_routes({'identify_of_route':YourScreen})NavigationConsider we have 2 screens as below inmain.pyfile.# Import Screens class from screens folderfromscreensimportScreen1,Screen2# The register_routes method requires a dictionary of Componentsapp.register_routes({'s1':Screen1's2':Screen2})We want to navigate fromScreen1toScreen2at logic method ofScreen1classScreen1:...deflogic(self,command,context):# Navigate to Screen 2 if user type `2`ifcommand=='2':# Use navigate method of Context and passing the key of Screencontext.navigate('s2')Global StateThe term of state management is strongly inspired by Redux library in React framework. It stores the value of and be accessing in diffirent Screens. Unlike the local varable that we define at the__init__method of a Screen which only accessed inside the class, this state can be store, update anywhere in your app.Create your state atstate/your_state.pyfile.fromterappimportState# Initialize store instancestore=State(init_state=0)# Create a name for an event and this actionstore.reducers(reducer='increase_count',action=lambdastate,payload:state+=payload)Import the store instance into the Screenfromstate.your_stateimportstoreclassScreen:...deflogic(self,command,context):# Increase the count value# Use dispatch method, access by the event name and passing new datastore.dispatch(reducer='increase_count',payload=int(command))Theinit_statecan be a dictionary or anythingstore=State(init_state={'name':"Ming Doan",'age':20})store.reducers(reducer='change_name',action=lambdastate,payload:{'name':payload# Update name})High level UITer is providing some quick UI in terminal app.HeaderfromterappimportHeaderclassScreen:...defrender(self,contex):print(Header(context,"This is header"))Future developmentTer was only the alpha version, the future update will arrive soon. (Depend on Author 😁🙌)Author & MaintainerMing DoanEmail:quangminh57dng@gmail.comGithub:https://github.com/Ming-doanFacebook:https://www.facebook.com/ming.doan/