This commit is contained in:
firebadnofire 2024-01-04 11:35:31 -05:00
parent 52b19ba762
commit d243c693cb
Signed by: firebadnofire
SSH Key Fingerprint: SHA256:bnN1TGRauJN84CxL1IZ/2uHNvJualwYkFjOKaaOilJE
5 changed files with 3 additions and 122 deletions

View File

@ -13,46 +13,14 @@ can he successfuly return to his own time?
# How to read this
```
Do not install the requirements.txt unless you are on windows.
```
Download the code and book:
Download the book:
```
git clone https://codeberg.org/firebadnofire/book.git
```
Windows only: install the requirements.txt
```
pip install -r requirements.txt
```
Run the reader program
```
python3 reader.py
```
Controls:
left/right: change chapter
up/down: scroll
q: quit
Open the .txt files in your favorite text editor
# License
The code has been licensed under the MIT license
Literary license:
The Future's Relic (c) by firebadnofire
The Future's Relic is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
You should have received a copy of the license along with this
work. If not, see <https://creativecommons.org/licenses/by-nc-sa/4.0/>.
The Future's Relic © 2024 by firebadnofire is licensed under Attribution-NonCommercial-ShareAlike 4.0 International. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/

View File

@ -1,9 +0,0 @@
MIT License
Copyright (c) 2023 firebadnofire
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -1,77 +0,0 @@
import curses
import os
import textwrap
def read_file(filename):
with open(filename, 'r', encoding='utf-8') as f:
return f.read()
def main(stdscr):
curses.curs_set(0) # Hide cursor
stdscr.keypad(1) # Enable special keys
stdscr.timeout(100) # Set timeout for getch
current_chapter = 0
offset = 0 # To keep track of scrolling
update_needed = True # Flag to check whether an update is needed
while True:
# Only clear and refresh the screen if an update is needed
if update_needed:
stdscr.clear()
# Read the file
if current_chapter == 0:
text = read_file('chapters/title.txt')
else:
text = read_file(f'chapters/chapter{current_chapter}.txt')
# Split text by lines, then wrap each line
max_y, max_x = stdscr.getmaxyx()
lines = text.split('\n')
wrapped_lines = [textwrap.fill(line, width=max_x) for line in lines]
final_text = '\n'.join(wrapped_lines)
final_lines = final_text.split('\n')
# Display text
for i, line in enumerate(final_lines[offset:]):
if i >= max_y - 1:
break
stdscr.addstr(i, 0, line)
stdscr.refresh()
update_needed = False # Reset the flag after updating
# Get user input
c = stdscr.getch()
# Scroll up/down
if c == curses.KEY_UP and offset > 0:
offset -= 1
update_needed = True
elif c == curses.KEY_DOWN and offset < len(final_lines) - max_y:
offset += 1
update_needed = True
# Skip a whole screen up/down
elif c == curses.KEY_SR and offset > 0: # Ctrl+Up
offset = max(0, offset - max_y)
update_needed = True
elif c == curses.KEY_SF and offset < len(final_lines) - max_y: # Ctrl+Down
offset = min(len(final_lines) - max_y, offset + max_y)
update_needed = True
# Change chapters
elif c == curses.KEY_RIGHT:
current_chapter += 1
if not os.path.exists(f'chapters/chapter{current_chapter}.txt'):
current_chapter -= 1
offset = 0
update_needed = True
elif c == curses.KEY_LEFT and current_chapter > 0:
current_chapter -= 1
offset = 0
update_needed = True
# Quit
elif c == ord('q'):
break # No need to set update_needed since we are exiting
curses.wrapper(main)

View File

@ -1 +0,0 @@
windows-curses