-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdijkstrapy.py
75 lines (64 loc) · 2.14 KB
/
dijkstrapy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import getchar
import os
import var
import screen
import handler
import readconfig
# CHANGED: introduce math functions (sqrt, cos, sin, tan)
# CHANGED: move to float
# CHANGED: allow decimal input
# CHANGED: delete particular stacks
# CHANGED: Add help
# CHANGED: Modularised
# CHANGED: support erasing
# CHANGED: support entering negative numbers (\-)
# CHANGED: add scientific notation (E?)
# CHANGED: Added colour code
# TODO: functions to add possibly: root, npr, ncr
# TODO: imaginary number support
# TODO: reorder system functions so that they are in logical order on man page
# TODO: add number history
# TODO: round function
# TODO: settings? (write in scientific notation, turn colours on/off, change command keys) do we need ncurses
screen.clear()
readconfig.load_config()
readconfig.read_argv()
if os.name == 'nt':
import win10col
win10col.enable_VT()
screen.draw()
while True:
var.key = getchar._Getch()()
if var.key == '\b' and var.curs_pos < 1:
continue
elif var.key in var.SYS_COMMANDS:
var.SYS_COMMANDS[var.key]()
# Don't write RCs
if var.key == '\r' or var.key == '\b':
continue
#colour
if var.conf_ansi:
if var.key.isalpha():
screen.write_custom(var.key, var.conf_colour_alpha)
var.curs_pos += 1
elif var.key in var.ADV_OPERATORS:
pass
# screen.write_custom(var.key, 'red')
else:
screen.write(var.key)
var.curs_pos += 1
else:
screen.write(var.key)
var.curs_pos += 1
if var.key.isdigit():
handler.num_handle()
#this is needed to prevent operators being handled by operator handler during help and recurs functions
elif var.key.isalpha() or var.key in var.ADV_OPERATORS or var.key =='?':
handler.character_handler(var.key) #character handler does not check whether there is a number waiting to be pushed to stack
elif var.key == '.':
if var.number:
var.number = var.number+'.'
else:
var.number = '.'
if var.key != '\b':
var.lastkey = var.key