├── LICENSE ├── README.md ├── demo.py └── terminal.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 4dc5 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Make a configurable display environment for the Casio fx-CG50. 2 | 3 | To use, do this in your file: 4 | 5 | from terminal.py import * 6 | 7 | term=Terminal() 8 | 9 | term.xprint("String to display") 10 | 11 | For different colors, try for example: 12 | 13 | term=Terminal(bg=(0,255,255),fg=(255,0,0)) 14 | 15 | Note that this package relies on the casioplot package which was added to version 3.40 of the OS. If you're on an older version, you'll need to update: https://edu.casio.com/download/index.php 16 | 17 | -- 18 | 4dc5.com 19 | -------------------------------------------------------------------------------- /demo.py: -------------------------------------------------------------------------------- 1 | from terminal import * 2 | 3 | term=Terminal() 4 | 5 | term.xprint("Short lines are OK.") 6 | term.xprint("But long lines are OK too because they will be wrapped.") 7 | term.xprint("It does not have to be text.") 8 | term.xprint(42) 9 | term.xprint("That is a number and it is OK.") 10 | 11 | term.xprint("We handle scrolling too.") 12 | for i in range(0,10): 13 | term.xprint(i) 14 | 15 | term=Terminal(bg=(0,255,255),fg=(255,0,0)) 16 | 17 | term.xprint("But we can choose other colors too!") 18 | -------------------------------------------------------------------------------- /terminal.py: -------------------------------------------------------------------------------- 1 | from casioplot import * 2 | 3 | # Make a configurable display environment for the Casio fx-CG50. 4 | # 5 | # To use, do this in your file: 6 | # from terminal.py import * 7 | # term=Terminal() 8 | # term.xprint("String to display") 9 | # 10 | # For different colors, try for example: 11 | # term=Terminal(bg=(0,255,255),fg=(255,0,0)) 12 | 13 | class Terminal: 14 | 15 | # Default to black background and green foreground. Set bg and/or fg to change this. 16 | def __init__(self,bg=(0,0,0),fg=(0,255,0)): 17 | self.scr=[] # The screen buffer 18 | self.bg=bg 19 | self.fg=fg 20 | self.rows=11 # Text rows 21 | self.cols=34 # Text columns 22 | self.clear() 23 | 24 | # Clear the screen. 25 | def clear(self): 26 | # We print the letter 'T' all over the screen. Do it as little as possible, for speed. 27 | for y in range(0,189,3): 28 | for x in range(0,3): 29 | draw_string(x,y,"T"*32,self.bg) 30 | # We missed some pixels at the bottom of the screen, so fill them in now. 31 | for x in range(0,3): 32 | draw_string(x,189,"T"*32,self.bg) 33 | 34 | # Refresh the screen with whatever we have in the buffer. 35 | def refresh(self): 36 | self.clear() 37 | # We only want the number of rows we can fit on the screen, so truncate the buffer. 38 | self.scr=self.scr[-self.rows:] 39 | # Write the buffer rows to the screen. 40 | y=0 41 | for r in self.scr: 42 | draw_string(5,8+y*16,r,self.fg) 43 | y+=1 44 | show_screen() 45 | 46 | # Print a string on the screen. 47 | def xprint(self,s): 48 | s=str(s) 49 | self.scr.extend(self._lines(s)) 50 | self.refresh() 51 | 52 | # Split a string into a number of lines that will fit within the screen width. 53 | def _lines(self,s): 54 | r=[] 55 | while len(s)>self.cols: 56 | r.append(s[:self.cols]) 57 | s=s[-(len(s)-self.cols):] 58 | if len(s)>0: 59 | r.append(s) 60 | return r 61 | 62 | --------------------------------------------------------------------------------