-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpnimrp.nim
84 lines (68 loc) · 2.37 KB
/
pnimrp.nim
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
76
77
78
79
80
81
82
83
84
import
os, src/[menu, ui, illwill,
theme], terminal, strformat,
std/exitprocs
type
AppConfig = object
assetsDir: string # Directory where application assets are stored
version: string # Application version
const
AppName = "Poor Man's Radio Player" # Name of the application
Version = "1.0.0" # Current version of the application
RequiredAssets = [
"quote.json" # List of required asset files (can be expanded as needed)
]
proc validateEnvironment() =
## Validates the application environment, ensuring necessary assets and permissions are in place.
let assetsDir = getAppDir() / "assets"
# Ensure the assets directory exists
if not dirExists(assetsDir):
error "Assets directory not found: " & assetsDir
# Future: Add checks for required assets and write permissions if needed
proc getAppConfig(): AppConfig =
## Initializes and returns the application configuration.
result = AppConfig(
assetsDir: getAppDir() / "assets", # Set the assets directory path
version: Version # Set the application version
)
proc showBanner() =
## Displays the application banner with version and copyright information.
styledEcho(fgCyan, fmt"""
{AppName} v{Version}
Copyright (c) 2021-2024
""")
proc cleanup() =
## Performs cleanup tasks on application exit, such as restoring the cursor.
showCursor()
echo ""
echo "Thank you for using " & AppName
when defined(dragonfly):
{.error: """
PNimRP is not supported under DragonFlyBSD
Please see user.rst for more information.
""".}
proc main() =
## Main entry point for the application.
try:
# Register cleanup procedure to run on exit
addExitProc(cleanup)
# Load theme configuration
let configPath = getAppDir() / "assets" / "config" / "themes.json"
var themeConfig = loadThemeConfig(configPath)
currentTheme = getCurrentTheme(themeConfig)
# Validate the environment and initialize configuration
validateEnvironment()
let config = getAppConfig()
# Display the application banner and hide the cursor
showBanner()
hideCursor()
# Start the main menu with the configured assets directory
drawMainMenu(config.assetsDir)
except Exception as e:
# Handle any fatal errors that occur during execution
error "Fatal error: " & e.msg
finally:
# Ensure cleanup is always performed
cleanup()
when isMainModule:
main()