1use lazy_static::lazy_static;
2use std::env;
3
4lazy_static! {
5 pub static ref FAKE_PTY: bool = env::var("rstask_FAKE_PTY").is_ok();
6}
7
8pub const VERSION: &str = env!("CARGO_PKG_VERSION");
10pub fn git_commit() -> &'static str {
12 option_env!("GIT_COMMIT").unwrap_or("Unknown")
13}
14
15pub fn build_date() -> &'static str {
16 option_env!("BUILD_DATE").unwrap_or("Unknown")
17}
18
19pub const STATUS_PENDING: &str = "pending";
21pub const STATUS_ACTIVE: &str = "active";
22pub const STATUS_RESOLVED: &str = "resolved";
23pub const STATUS_DELEGATED: &str = "delegated";
24pub const STATUS_DEFERRED: &str = "deferred";
25pub const STATUS_PAUSED: &str = "paused";
26pub const STATUS_RECURRING: &str = "recurring";
27pub const STATUS_TEMPLATE: &str = "template";
28
29pub const CMD_NEXT: &str = "next";
31pub const CMD_ADD: &str = "add";
32pub const CMD_RM: &str = "rm";
33pub const CMD_REMOVE: &str = "remove";
34pub const CMD_TEMPLATE: &str = "template";
35pub const CMD_LOG: &str = "log";
36pub const CMD_START: &str = "start";
37pub const CMD_NOTE: &str = "note";
38pub const CMD_NOTES: &str = "notes";
39pub const CMD_STOP: &str = "stop";
40pub const CMD_DONE: &str = "done";
41pub const CMD_RESOLVE: &str = "resolve";
42pub const CMD_CONTEXT: &str = "context";
43pub const CMD_MODIFY: &str = "modify";
44pub const CMD_EDIT: &str = "edit";
45pub const CMD_UNDO: &str = "undo";
46pub const CMD_SYNC: &str = "sync";
47pub const CMD_OPEN: &str = "open";
48pub const CMD_SHOW: &str = "show";
49pub const CMD_GIT: &str = "git";
50pub const CMD_SHOW_NEXT: &str = "show-next";
51pub const CMD_SHOW_PROJECTS: &str = "show-projects";
52pub const CMD_SHOW_TAGS: &str = "show-tags";
53pub const CMD_SHOW_ACTIVE: &str = "show-active";
54pub const CMD_SHOW_PAUSED: &str = "show-paused";
55pub const CMD_SHOW_OPEN: &str = "show-open";
56pub const CMD_SHOW_RESOLVED: &str = "show-resolved";
57pub const CMD_SHOW_TEMPLATES: &str = "show-templates";
58pub const CMD_SHOW_UNORGANISED: &str = "show-unorganised";
59pub const CMD_COMPLETIONS: &str = "_completions";
60pub const CMD_HELP: &str = "help";
61pub const CMD_VERSION: &str = "version";
62pub const CMD_PRINT_ZSH_COMPLETION: &str = "zsh-completion";
63pub const CMD_PRINT_BASH_COMPLETION: &str = "bash-completion";
64pub const CMD_PRINT_FISH_COMPLETION: &str = "fish-completion";
65
66pub const PRIORITY_CRITICAL: &str = "P0";
68pub const PRIORITY_HIGH: &str = "P1";
69pub const PRIORITY_NORMAL: &str = "P2";
70pub const PRIORITY_LOW: &str = "P3";
71
72pub const MAX_TASKS_OPEN: usize = 10000;
74pub const TASK_FILENAME_LEN: usize = 40;
75pub const MIN_TASKS_SHOWN: usize = 8;
76pub const TERMINAL_HEIGHT_MARGIN: usize = 9;
77pub const IGNORE_CONTEXT_KEYWORD: &str = "--";
78pub const NOTE_MODE_KEYWORD: &str = "/";
79
80pub const TABLE_MAX_WIDTH: usize = 160;
82pub const TABLE_COL_GAP: usize = 2;
83pub const MODE_HEADER: u8 = 4;
84pub const FG_DEFAULT: u8 = 250;
85pub const BG_DEFAULT_1: u8 = 233;
86pub const BG_DEFAULT_2: u8 = 232;
87pub const MODE_DEFAULT: u8 = 0;
88pub const FG_ACTIVE: u8 = 233;
89pub const BG_ACTIVE: u8 = 250;
90pub const BG_PAUSED: u8 = 236;
91pub const FG_PRIORITY_CRITICAL: u8 = 160;
92pub const FG_PRIORITY_HIGH: u8 = 166;
93pub const FG_PRIORITY_NORMAL: u8 = FG_DEFAULT;
94pub const FG_PRIORITY_LOW: u8 = 245;
95pub const FG_ACTIVE_PRIORITY_CRITICAL: u8 = 124;
96pub const FG_ACTIVE_PRIORITY_HIGH: u8 = 130;
97pub const FG_ACTIVE_PRIORITY_LOW: u8 = 238;
98pub const FG_NOTE: u8 = 240;
99
100pub const ALL_STATUSES: &[&str] = &[
102 STATUS_ACTIVE,
103 STATUS_PENDING,
104 STATUS_DELEGATED,
105 STATUS_DEFERRED,
106 STATUS_PAUSED,
107 STATUS_RECURRING,
108 STATUS_RESOLVED,
109 STATUS_TEMPLATE,
110];
111
112pub const HIDDEN_STATUSES: &[&str] = &[STATUS_RECURRING, STATUS_RESOLVED, STATUS_TEMPLATE];
113
114pub const NON_RESOLVED_STATUSES: &[&str] = &[
115 STATUS_ACTIVE,
116 STATUS_PENDING,
117 STATUS_DELEGATED,
118 STATUS_DEFERRED,
119 STATUS_PAUSED,
120 STATUS_RECURRING,
121 STATUS_TEMPLATE,
122];
123
124pub const VALID_STATUS_TRANSITIONS: &[(&str, &str)] = &[
126 (STATUS_PENDING, STATUS_ACTIVE),
127 (STATUS_ACTIVE, STATUS_PAUSED),
128 (STATUS_PAUSED, STATUS_ACTIVE),
129 (STATUS_PENDING, STATUS_RESOLVED),
130 (STATUS_PAUSED, STATUS_RESOLVED),
131 (STATUS_ACTIVE, STATUS_RESOLVED),
132 (STATUS_PENDING, STATUS_TEMPLATE),
133 (STATUS_RESOLVED, STATUS_PENDING),
135 (STATUS_RESOLVED, STATUS_ACTIVE),
136 (STATUS_RESOLVED, STATUS_PAUSED),
137];
138
139pub const ALL_CMDS: &[&str] = &[
140 CMD_NEXT,
141 CMD_ADD,
142 CMD_RM,
143 CMD_REMOVE,
144 CMD_TEMPLATE,
145 CMD_LOG,
146 CMD_START,
147 CMD_NOTE,
148 CMD_NOTES,
149 CMD_STOP,
150 CMD_DONE,
151 CMD_RESOLVE,
152 CMD_CONTEXT,
153 CMD_MODIFY,
154 CMD_EDIT,
155 CMD_UNDO,
156 CMD_SYNC,
157 CMD_OPEN,
158 CMD_SHOW,
159 CMD_GIT,
160 CMD_SHOW_NEXT,
161 CMD_SHOW_PROJECTS,
162 CMD_SHOW_TAGS,
163 CMD_SHOW_ACTIVE,
164 CMD_SHOW_PAUSED,
165 CMD_SHOW_OPEN,
166 CMD_SHOW_RESOLVED,
167 CMD_SHOW_TEMPLATES,
168 CMD_SHOW_UNORGANISED,
169 CMD_COMPLETIONS,
170 CMD_PRINT_BASH_COMPLETION,
171 CMD_PRINT_FISH_COMPLETION,
172 CMD_PRINT_ZSH_COMPLETION,
173 CMD_HELP,
174 CMD_VERSION,
175];
176
177pub fn is_valid_status(status: &str) -> bool {
179 ALL_STATUSES.contains(&status)
180}
181
182pub fn is_valid_priority(priority: &str) -> bool {
183 matches!(
184 priority,
185 PRIORITY_CRITICAL | PRIORITY_HIGH | PRIORITY_NORMAL | PRIORITY_LOW
186 )
187}
188
189pub fn is_valid_status_transition(from: &str, to: &str) -> bool {
190 VALID_STATUS_TRANSITIONS.contains(&(from, to))
191}