Skip to content

Commit 56fbab6

Browse files
committed
refactor: simplify config
1 parent 67b30c3 commit 56fbab6

File tree

7 files changed

+43
-120
lines changed

7 files changed

+43
-120
lines changed

default-config.kdl renamed to default.kdl

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,8 @@ default-image-upload-provider the-null-pointer
66
size-indicator #true
77
instant #false
88

9-
theme {
10-
selection-frame 0xab_61_37
11-
12-
non-selected-region 0x00_00_00 opacity=0.5
13-
14-
drop-shadow 0x00_00_00 opacity=0.5
15-
16-
text-selection 0xab_61_37 opacity=0.3
17-
18-
size-indicator-fg 0xff_ff_ff
19-
size-indicator-bg 0x00_00_00 opacity=0.5
20-
21-
tooltip-fg 0xff_ff_ff
22-
tooltip-bg 0x00_00_00
23-
24-
error-fg 0xff_ff_ff
25-
error-bg 0xff_00_00 opacity=0.6
26-
27-
info-box-fg 0xff_ff_ff
28-
info-box-bg 0xab_61_37 opacity=0.95
29-
30-
icon-fg 0xff_ff_ff
31-
icon-bg 0xab_61_37
32-
}
33-
349
keys {
35-
exit key=<escape>
10+
exit key=<esc>
3611

3712
copy-to-clipboard mod=ctrl key=c
3813
copy-to-clipboard key=<enter>
@@ -101,16 +76,38 @@ keys {
10176
shrink right 5 mod="ctrl + alt" key=l
10277
shrink right 5 mod="ctrl + alt" key=<right>
10378

104-
// "teleport" the selection to a place
105-
goto left key=gh
106-
goto bottom key=gj
107-
goto top key=gk
108-
goto right key=gl
109-
110-
goto center key=gc
111-
goto top-left key=gg
112-
goto top-right key=>
113-
goto bottom-left key=<
114-
goto bottom-right key=G
79+
// move selection as far as it can go
80+
move left #inf key=gh
81+
move left #inf key=g<left>
82+
move down #inf key=gj
83+
move down #inf key=g<down>
84+
move up #inf key=gk
85+
move up #inf key=g<up>
86+
move right #inf key=gl
87+
move right #inf key=g<right>
11588
}
11689

90+
theme {
91+
selection-frame 0xab_61_37
92+
93+
non-selected-region 0x00_00_00 opacity=0.5
94+
95+
drop-shadow 0x00_00_00 opacity=0.5
96+
97+
text-selection 0xab_61_37 opacity=0.3
98+
99+
size-indicator-fg 0xff_ff_ff
100+
size-indicator-bg 0x00_00_00 opacity=0.5
101+
102+
tooltip-fg 0xff_ff_ff
103+
tooltip-bg 0x00_00_00
104+
105+
error-fg 0xff_ff_ff
106+
error-bg 0xff_00_00 opacity=0.6
107+
108+
info-box-fg 0xff_ff_ff
109+
info-box-bg 0xab_61_37 opacity=0.95
110+
111+
icon-fg 0xff_ff_ff
112+
icon-bg 0xab_61_37
113+
}

src/app.rs

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use iced::widget::{self, Column, Space, Stack, canvas, column, container, row};
1717
use iced::{Background, Color, Element, Font, Length, Point, Rectangle, Size, Task};
1818

1919
use crate::background_image::BackgroundImage;
20-
use crate::corners::{Corner, Direction, RectPlace, Side, SideOrCorner};
20+
use crate::corners::{Corner, Direction, Side, SideOrCorner};
2121
use crate::rectangle::RectangleExt;
2222
use crate::selection::{Selection, SelectionStatus};
2323

@@ -334,48 +334,6 @@ impl App {
334334
return Self::exit();
335335
}
336336
KeyAction::Exit => return Self::exit(),
337-
KeyAction::Goto(rect_place) => {
338-
let Some(selection) = self.selection.as_mut() else {
339-
self.error("Nothing is selected.");
340-
return Task::none();
341-
};
342-
let sel = selection.norm();
343-
let (image_width, image_height, _) = self.screenshot.raw();
344-
let image_height = image_height as f32;
345-
let image_width = image_width as f32;
346-
347-
*selection = match rect_place {
348-
RectPlace::SideOrCorner(SideOrCorner::Side(side)) => match side {
349-
Side::Top => sel
350-
.with_x(|_| image_width / 2.0 - sel.rect.width / 2.0)
351-
.with_y(|_| 0.0),
352-
Side::Right => sel
353-
.with_x(|_| image_width - sel.rect.width)
354-
.with_y(|_| image_height / 2.0 - sel.rect.height / 2.0),
355-
Side::Bottom => sel
356-
.with_x(|_| image_width / 2.0 - sel.rect.width / 2.0)
357-
.with_y(|_| image_height - sel.rect.height),
358-
Side::Left => sel
359-
.with_x(|_| 0.0)
360-
.with_y(|_| image_height / 2.0 - sel.rect.height / 2.0),
361-
},
362-
RectPlace::SideOrCorner(SideOrCorner::Corner(corner)) => match corner {
363-
Corner::TopLeft => sel.with_x(|_| 0.0).with_y(|_| 0.0),
364-
Corner::TopRight => {
365-
sel.with_x(|_| image_width - sel.rect.width).with_y(|_| 0.0)
366-
}
367-
Corner::BottomLeft => sel
368-
.with_x(|_| 0.0)
369-
.with_y(|_| image_height - sel.rect.height),
370-
Corner::BottomRight => sel
371-
.with_x(|_| image_width - sel.rect.width)
372-
.with_y(|_| image_height - sel.rect.height),
373-
},
374-
RectPlace::Center => sel
375-
.with_x(|_| image_width / 2.0 - sel.rect.width / 2.0)
376-
.with_y(|_| image_height / 2.0 - sel.rect.height / 2.0),
377-
};
378-
}
379337
KeyAction::Move(direction, amount) => {
380338
println!("{direction:?}, {amount:?}");
381339
let Some(selection) = self.selection.as_mut() else {

src/config/mod.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ pub mod key;
1919
pub mod macros;
2020
pub mod named_key;
2121

22-
/// The default configuration for ferrishot, to be *merged* with the user's config
23-
pub const DEFAULT_KDL_CONFIG_STR: &str = include_str!("../../default-config.kdl");
22+
/// The default configuration for ferrishot, to be merged with the user's config
23+
pub const DEFAULT_KDL_CONFIG_STR: &str = include_str!("../../default.kdl");
2424

2525
use crate::config::key::KeyMap;
2626
use crate::config::macros::Color;
2727
use crate::corners::Direction;
28-
use crate::corners::RectPlace;
2928
use crate::image_upload::ImageUploadService;
3029
pub use cli::CLI;
3130
use std::fs;
@@ -62,11 +61,6 @@ crate::declare_key_options! {
6261
Exit,
6362
/// Set selection to encompass the entire screen
6463
SelectFullScreen,
65-
/// Teleport the selection to the given area
66-
Goto {
67-
#[knus(str)]
68-
place: RectPlace,
69-
},
7064
/// Shift the selection in the given direction by pixels
7165
Move {
7266
direction: Direction,

src/config/named_key.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ named_keys! {
3535
ArrowLeft = "left",
3636
ArrowRight = "right",
3737
ArrowUp = "up",
38+
Escape = "esc",
3839
Alt,
3940
AltGraph,
4041
CapsLock,
@@ -73,7 +74,6 @@ named_keys! {
7374
Attn,
7475
Cancel,
7576
ContextMenu,
76-
Escape,
7777
Execute,
7878
Find,
7979
Help,

src/corners.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -123,34 +123,6 @@ impl FromStr for SideOrCorner {
123123

124124
/// A named place of the rectangle
125125
126-
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
127-
pub enum RectPlace {
128-
/// A side or a corner of the rectangle
129-
SideOrCorner(SideOrCorner),
130-
/// Center of the rectangle
131-
Center,
132-
}
133-
134-
impl FromStr for RectPlace {
135-
type Err = String;
136-
137-
fn from_str(s: &str) -> Result<Self, Self::Err> {
138-
s.parse::<SideOrCorner>().map_or_else(
139-
|_| {
140-
if s == "center" {
141-
Ok(Self::Center)
142-
} else {
143-
Err(format!(
144-
"expected one of center, {}",
145-
SideOrCorner::variants()
146-
))
147-
}
148-
},
149-
|side_or_corner| Ok(Self::SideOrCorner(side_or_corner)),
150-
)
151-
}
152-
}
153-
154126
impl Corner {
155127
/// # Arguments
156128
///

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ fn main() -> miette::Result<()> {
3333
)
3434
.into_diagnostic()?;
3535
std::fs::write(&CLI.config_file, ferrishot::DEFAULT_KDL_CONFIG_STR).into_diagnostic()?;
36+
println!("Success");
3637

3738
return Ok(());
3839
}

src/message.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
//! A message represents some event in the app that mutates the state
22
3-
use iced::{Point, Rectangle, mouse::Cursor, wgpu::hal::DynPipelineCache};
3+
use iced::{Point, Rectangle, mouse::Cursor};
44

55
use crate::{
6-
corners::{Direction, RectPlace, SideOrCorner},
6+
config::KeyAction,
7+
corners::SideOrCorner,
78
selection::{Selection, Speed, selection_lock::SelectionIsSome},
89
};
910

@@ -80,5 +81,5 @@ pub enum Message {
8081
sel_is_some: SelectionIsSome,
8182
},
8283
/// An action can be triggered by a keybind
83-
KeyBind(crate::config::KeyAction),
84+
KeyBind(KeyAction),
8485
}

0 commit comments

Comments
 (0)