@@ -8,12 +8,8 @@ use alacritty_terminal::grid::GridCell;
88use alacritty_terminal:: term:: cell:: Flags ;
99use alacritty_terminal:: term:: TermMode ;
1010use alacritty_terminal:: vte:: ansi:: { Color , NamedColor } ;
11- use copypasta:: ClipboardProvider ;
1211use egui:: epaint:: RectShape ;
13- use egui:: {
14- Align2 , Button , CornerRadius , CursorIcon , Key , KeyboardShortcut , Modifiers , Painter , Pos2 ,
15- Rect , Response , Vec2 , WidgetText ,
16- } ;
12+ use egui:: { Align2 , CornerRadius , CursorIcon , Painter , Pos2 , Rect , Response , Vec2 } ;
1713use egui:: { Shape , Stroke } ;
1814
1915impl TerminalView < ' _ > {
@@ -146,75 +142,3 @@ impl TerminalView<'_> {
146142 painter. extend ( shapes) ;
147143 }
148144}
149-
150- impl TerminalView < ' _ > {
151- pub fn context_menu ( & mut self , layout : & Response ) {
152- layout. context_menu ( |ui| {
153- let width = 200. ;
154- ui. set_width ( width) ;
155- // copy btn
156- self . copy_btn ( ui, layout, width) ;
157- // paste btn
158- self . paste_btn ( ui, width) ;
159-
160- ui. separator ( ) ;
161- // select all btn
162- self . select_all_btn ( ui, width) ;
163- } ) ;
164- }
165-
166- fn copy_btn ( & mut self , ui : & mut egui:: Ui , layout : & Response , btn_width : f32 ) {
167- #[ cfg( not( target_os = "macos" ) ) ]
168- let copy_shortcut = KeyboardShortcut :: new ( Modifiers :: CTRL | Modifiers :: SHIFT , Key :: C ) ;
169- #[ cfg( target_os = "macos" ) ]
170- let copy_shortcut = KeyboardShortcut :: new ( Modifiers :: MAC_CMD , Key :: C ) ;
171- let copy_shortcut = ui. ctx ( ) . format_shortcut ( & copy_shortcut) ;
172- let copy_btn = context_btn ( "Copy" , btn_width, Some ( copy_shortcut) ) ;
173- if ui. add ( copy_btn) . clicked ( ) {
174- let data = self . term_ctx . selection_content ( ) ;
175- layout. ctx . copy_text ( data) ;
176- ui. close ( ) ;
177- }
178- }
179-
180- fn paste_btn ( & mut self , ui : & mut egui:: Ui , btn_width : f32 ) {
181- #[ cfg( not( target_os = "macos" ) ) ]
182- let paste_shortcut = KeyboardShortcut :: new ( Modifiers :: CTRL | Modifiers :: SHIFT , Key :: V ) ;
183- #[ cfg( target_os = "macos" ) ]
184- let paste_shortcut = KeyboardShortcut :: new ( Modifiers :: MAC_CMD , Key :: V ) ;
185- let paste_shortcut = ui. ctx ( ) . format_shortcut ( & paste_shortcut) ;
186- let paste_btn = context_btn ( "Paste" , btn_width, Some ( paste_shortcut) ) ;
187- if ui. add ( paste_btn) . clicked ( ) {
188- if let Ok ( data) = self . term_ctx . clipboard . get_contents ( ) {
189- self . term_ctx . write_data ( data. into_bytes ( ) ) ;
190- self . term_ctx . terminal . selection = None ;
191- }
192- ui. close ( ) ;
193- }
194- }
195-
196- fn select_all_btn ( & mut self , ui : & mut egui:: Ui , btn_width : f32 ) {
197- #[ cfg( not( target_os = "macos" ) ) ]
198- let select_all_shortcut = KeyboardShortcut :: new ( Modifiers :: CTRL , Key :: A ) ;
199- #[ cfg( target_os = "macos" ) ]
200- let select_all_shortcut = KeyboardShortcut :: new ( Modifiers :: MAC_CMD , Key :: A ) ;
201- let select_all_shortcut = ui. ctx ( ) . format_shortcut ( & select_all_shortcut) ;
202- let select_all_btn = context_btn ( "Select All" , btn_width, Some ( select_all_shortcut) ) ;
203- if ui. add ( select_all_btn) . clicked ( ) {
204- self . term_ctx . select_all ( ) ;
205- ui. close ( ) ;
206- }
207- }
208- }
209-
210- fn context_btn < ' a > (
211- text : impl Into < WidgetText > ,
212- width : f32 ,
213- shortcut : Option < String > ,
214- ) -> Button < ' a > {
215- let mut btn = Button :: new ( text) . min_size ( ( width, 0. ) . into ( ) ) ;
216- if let Some ( shortcut) = shortcut {
217- btn = btn. shortcut_text ( shortcut) ;
218- }
219- btn
220- }
0 commit comments