@@ -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 , Area , Button , Color32 , CornerRadius , CursorIcon , Id , Key , KeyboardShortcut , Modifiers ,
15- Painter , Pos2 , Rect , Response , Vec2 , WidgetText ,
16- } ;
12+ use egui:: { Align2 , CornerRadius , CursorIcon , Painter , Pos2 , Rect , Response , Vec2 } ;
1713use egui:: { Shape , Stroke } ;
1814
1915impl TerminalView < ' _ > {
@@ -146,82 +142,3 @@ impl TerminalView<'_> {
146142 painter. extend ( shapes) ;
147143 }
148144}
149-
150- impl TerminalView < ' _ > {
151- pub fn context_menu ( & mut self , pos : Pos2 , layout : & Response , ui : & mut egui:: Ui ) {
152- Area :: new ( Id :: new ( format ! ( "context_menu_{:?}" , self . id( ) ) ) )
153- . fixed_pos ( pos)
154- . order ( egui:: Order :: Foreground )
155- . show ( ui. ctx ( ) , |ui| {
156- egui:: Frame :: popup ( ui. style ( ) ) . show ( ui, |ui| {
157- let width = 200. ;
158- ui. set_width ( width) ;
159- // copy btn
160- self . copy_btn ( ui, layout, width) ;
161- // paste btn
162- self . paste_btn ( ui, width) ;
163-
164- ui. separator ( ) ;
165- // select all btn
166- self . select_all_btn ( ui, width) ;
167- } ) ;
168- } ) ;
169- }
170-
171- fn copy_btn ( & mut self , ui : & mut egui:: Ui , layout : & Response , btn_width : f32 ) {
172- #[ cfg( not( target_os = "macos" ) ) ]
173- let copy_shortcut = KeyboardShortcut :: new ( Modifiers :: CTRL | Modifiers :: SHIFT , Key :: C ) ;
174- #[ cfg( target_os = "macos" ) ]
175- let copy_shortcut = KeyboardShortcut :: new ( Modifiers :: MAC_CMD , Key :: C ) ;
176- let copy_shortcut = ui. ctx ( ) . format_shortcut ( & copy_shortcut) ;
177- let copy_btn = context_btn ( "Copy" , btn_width, Some ( copy_shortcut) ) ;
178- if ui. add ( copy_btn) . clicked ( ) {
179- let data = self . term_ctx . selection_content ( ) ;
180- layout. ctx . copy_text ( data) ;
181- ui. close ( ) ;
182- }
183- }
184-
185- fn paste_btn ( & mut self , ui : & mut egui:: Ui , btn_width : f32 ) {
186- #[ cfg( not( target_os = "macos" ) ) ]
187- let paste_shortcut = KeyboardShortcut :: new ( Modifiers :: CTRL | Modifiers :: SHIFT , Key :: V ) ;
188- #[ cfg( target_os = "macos" ) ]
189- let paste_shortcut = KeyboardShortcut :: new ( Modifiers :: MAC_CMD , Key :: V ) ;
190- let paste_shortcut = ui. ctx ( ) . format_shortcut ( & paste_shortcut) ;
191- let paste_btn = context_btn ( "Paste" , btn_width, Some ( paste_shortcut) ) ;
192- if ui. add ( paste_btn) . clicked ( ) {
193- if let Ok ( data) = self . term_ctx . clipboard . get_contents ( ) {
194- self . term_ctx . write_data ( data. into_bytes ( ) ) ;
195- self . term_ctx . terminal . selection = None ;
196- }
197- ui. close ( ) ;
198- }
199- }
200-
201- fn select_all_btn ( & mut self , ui : & mut egui:: Ui , btn_width : f32 ) {
202- #[ cfg( not( target_os = "macos" ) ) ]
203- let select_all_shortcut = KeyboardShortcut :: new ( Modifiers :: CTRL , Key :: A ) ;
204- #[ cfg( target_os = "macos" ) ]
205- let select_all_shortcut = KeyboardShortcut :: new ( Modifiers :: MAC_CMD , Key :: A ) ;
206- let select_all_shortcut = ui. ctx ( ) . format_shortcut ( & select_all_shortcut) ;
207- let select_all_btn = context_btn ( "Select All" , btn_width, Some ( select_all_shortcut) ) ;
208- if ui. add ( select_all_btn) . clicked ( ) {
209- self . term_ctx . select_all ( ) ;
210- ui. close ( ) ;
211- }
212- }
213- }
214-
215- fn context_btn < ' a > (
216- text : impl Into < WidgetText > ,
217- width : f32 ,
218- shortcut : Option < String > ,
219- ) -> Button < ' a > {
220- let mut btn = Button :: new ( text)
221- . fill ( Color32 :: TRANSPARENT )
222- . min_size ( ( width, 0. ) . into ( ) ) ;
223- if let Some ( shortcut) = shortcut {
224- btn = btn. shortcut_text ( shortcut) ;
225- }
226- btn
227- }
0 commit comments