Skip to content

Commit b028ab5

Browse files
committed
test: add tests for config
1 parent a871f69 commit b028ab5

File tree

3 files changed

+210
-0
lines changed

3 files changed

+210
-0
lines changed

src/config/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
//! obtain the `Message` to execute for that action.
1515
//! - Adding opacity to colors
1616
17+
#[cfg(test)]
18+
mod tests;
19+
1720
pub mod cli;
1821
pub mod commands;
1922
pub mod key_map;
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
// This file is from the first version that the config became stable
2+
// We should never make a change that causes this file to fail to parse
3+
4+
// Default config for ferrishot
5+
//
6+
// Create this file in the appropriate place with `ferrishot --dump-default-config`
7+
//
8+
// You can remove all of the defaults, and just keep your overrides
9+
// if you want to do that
10+
11+
// Show the size indicator
12+
size-indicator #true
13+
// Show icons around the selection
14+
selection-icons #true
15+
16+
keys {
17+
// Leave the app
18+
exit key=<esc>
19+
20+
// Copies selected region to clipboard, exiting
21+
copy-to-clipboard mod=ctrl key=c
22+
copy-to-clipboard key=<enter>
23+
24+
// Save to a file
25+
save-screenshot mod=ctrl key=s
26+
27+
// Upload and make a link
28+
upload-screenshot mod=ctrl key=u
29+
30+
// Set selection to be the entire screen
31+
// You can use the syntax of `ferrishot --region` here (see `--help` for more info)
32+
select-region "full" key=<f11>
33+
34+
// Remove the selection
35+
clear-selection mod=ctrl key=x
36+
37+
// These 2 commands let you pick any area on the screen in 8 keystrokes
38+
pick-top-left-corner key=t
39+
pick-bottom-right-corner key=b
40+
41+
open-keybindings-cheatsheet key=?
42+
43+
// Set width/height to whatever is the current count.
44+
// You can change the count by just writing numbers. e.g. type `100X` to set
45+
// the width to 100px
46+
set-width key=X
47+
set-height key=Y
48+
49+
// move the selection in a direction by 1px
50+
move left 1 key=h
51+
move left 1 key=<left>
52+
move down 1 key=j
53+
move down 1 key=<down>
54+
move up 1 key=k
55+
move up 1 key=<up>
56+
move right 1 key=l
57+
move right 1 key=<right>
58+
59+
// extend a side by 1px
60+
extend left 1 key=H
61+
extend left 1 mod=shift key=<left>
62+
extend down 1 key=J
63+
extend down 1 mod=shift key=<down>
64+
extend up 1 key=K
65+
extend up 1 mod=shift key=<up>
66+
extend right 1 key=L
67+
extend right 1 mod=shift key=<right>
68+
69+
// shrink a side by 1px
70+
shrink left 1 mod=ctrl key=h
71+
shrink left 1 mod=ctrl key=<left>
72+
shrink down 1 mod=ctrl key=j
73+
shrink down 1 mod=ctrl key=<down>
74+
shrink up 1 mod=ctrl key=k
75+
shrink up 1 mod=ctrl key=<up>
76+
shrink right 1 mod=ctrl key=l
77+
shrink right 1 mod=ctrl key=<right>
78+
79+
// move rectangle in direction by 125px
80+
move left 125 mod=alt key=h
81+
move left 125 mod=alt key=<left>
82+
move down 125 mod=alt key=j
83+
move down 125 mod=alt key=<down>
84+
move up 125 mod=alt key=k
85+
move up 125 mod=alt key=<up>
86+
move right 125 mod=alt key=l
87+
move right 125 mod=alt key=<right>
88+
89+
// extend a side by 125px
90+
extend left 125 mod=alt key=H
91+
extend left 125 mod=alt+shift key=<left>
92+
extend down 125 mod=alt key=J
93+
extend down 125 mod=alt+shift key=<down>
94+
extend up 125 mod=alt key=K
95+
extend up 125 mod=alt+shift key=<up>
96+
extend right 125 mod=alt key=L
97+
extend right 125 mod=alt+shift key=<right>
98+
99+
// shrink a side by 125px
100+
shrink left 125 mod=ctrl+alt key=h
101+
shrink left 125 mod=ctrl+alt key=<left>
102+
shrink down 125 mod=ctrl+alt key=j
103+
shrink down 125 mod=ctrl+alt key=<down>
104+
shrink up 125 mod=ctrl+alt key=k
105+
shrink up 125 mod=ctrl+alt key=<up>
106+
shrink right 125 mod=ctrl+alt key=l
107+
shrink right 125 mod=ctrl+alt key=<right>
108+
109+
// move selection as far as it can go
110+
move left key=gh
111+
move left key=g<left>
112+
move down key=gj
113+
move down key=g<down>
114+
move up key=gk
115+
move up key=g<up>
116+
move right key=gl
117+
move right key=g<right>
118+
119+
// teleport the selection to a place
120+
goto top-left key=gg
121+
goto bottom-right key=G
122+
goto center key=gc
123+
goto x-center key=gx
124+
goto y-center key=gy
125+
126+
// for debugging / development
127+
toggle-debug-overlay key=<f12>
128+
}
129+
130+
// editing the `theme` section allows you to fully customize the appearance of ferrishot
131+
132+
theme {
133+
// Backslash `\` lets you split it the palette over multiple lines
134+
palette \
135+
accent = 0xab_61_37 \
136+
fg = 0xff_ff_ff \
137+
bg = 0x00_00_00
138+
139+
// color of the frame around the selection
140+
//
141+
// Uses the `accent` color from the `palette`
142+
selection-frame accent
143+
144+
// background color of the region that is not selected
145+
non-selected-region bg opacity=0.5
146+
147+
// small drop shadow used, an example is around the selection and also
148+
// around icons surrounding the selection
149+
drop-shadow bg opacity=0.5
150+
151+
// selected text, for instance when editing the size indicator
152+
text-selection accent opacity=0.3
153+
154+
size-indicator-fg fg
155+
size-indicator-bg bg opacity=0.5
156+
157+
tooltip-fg fg
158+
tooltip-bg bg
159+
160+
error-fg fg
161+
// Use a custom hex color
162+
error-bg 0xff_00_00 opacity=0.6
163+
164+
info-box-fg fg
165+
info-box-border fg
166+
info-box-bg accent opacity=0.95
167+
168+
icon-fg fg
169+
icon-bg accent
170+
171+
// letters let you pick any region of the screen in 8 clicks
172+
// keys: t (top left corner), b (bottom right corner)
173+
letters-lines fg
174+
letters-bg bg opacity=0.6
175+
letters-fg fg
176+
177+
// image uploaded popup (ctrl + U)
178+
image-uploaded-fg fg
179+
image-uploaded-bg bg opacity=0.9
180+
181+
// for example, the checkmark when you copy to clipboard
182+
success 0x00_ff_00
183+
184+
cheatsheet-bg bg
185+
cheatsheet-fg fg
186+
187+
popup-close-icon-bg bg opacity=0.0
188+
popup-close-icon-fg fg
189+
190+
// debug menu, for development (F12)
191+
debug-fg fg
192+
debug-label 0xff_00_00
193+
debug-bg bg opacity=0.9
194+
}
195+

src/config/tests/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use super::*;
2+
3+
mod kdl_config_backward_compatibility {
4+
#[test]
5+
fn v0_3() {
6+
super::Config::parse(concat!(
7+
env!("CARGO_MANIFEST_DIR"),
8+
"/src/config/tests/2025_05_17_ferrishot_v0.3.kdl"
9+
))
10+
.expect("ferrishot v0.3: The first released version of the config must never break");
11+
}
12+
}

0 commit comments

Comments
 (0)