Expand description
an application state dedicated to help
Fields§
§scroll: usize
§text_area: Area
Implementations§
source§impl HelpState
impl HelpState
sourcepub fn new(
tree_options: TreeOptions,
_screen: Screen,
con: &AppContext
) -> HelpState
pub fn new(
tree_options: TreeOptions,
_screen: Screen,
con: &AppContext
) -> HelpState
Examples found in repository?
src/app/panel_state.rs (line 168)
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
fn on_internal_generic(
&mut self,
_w: &mut W,
internal_exec: &InternalExecution,
input_invocation: Option<&VerbInvocation>,
_trigger_type: TriggerType,
app_state: &mut AppState,
cc: &CmdContext,
) -> Result<CmdResult, ProgramError> {
let con = &cc.app.con;
let screen = cc.app.screen;
let bang = input_invocation
.map(|inv| inv.bang)
.unwrap_or(internal_exec.bang);
Ok(match internal_exec.internal {
Internal::back => CmdResult::PopState,
Internal::copy_line | Internal::copy_path => {
#[cfg(not(feature = "clipboard"))]
{
CmdResult::error("Clipboard feature not enabled at compilation")
}
#[cfg(feature = "clipboard")]
{
if let Some(path) = self.selected_path() {
let path = path.to_string_lossy().to_string();
match terminal_clipboard::set_string(path) {
Ok(()) => CmdResult::Keep,
Err(_) => CmdResult::error("Clipboard error while copying path"),
}
} else {
CmdResult::error("Nothing to copy")
}
}
}
Internal::close_panel_ok => CmdResult::ClosePanel {
validate_purpose: true,
panel_ref: PanelReference::Active,
},
Internal::close_panel_cancel => CmdResult::ClosePanel {
validate_purpose: false,
panel_ref: PanelReference::Active,
},
#[cfg(unix)]
Internal::filesystems => {
let fs_state = crate::filesystems::FilesystemState::new(
self.selected_path(),
self.tree_options(),
con,
);
match fs_state {
Ok(state) => {
let bang = input_invocation
.map(|inv| inv.bang)
.unwrap_or(internal_exec.bang);
if bang && cc.app.preview_panel.is_none() {
CmdResult::NewPanel {
state: Box::new(state),
purpose: PanelPurpose::None,
direction: HDir::Right,
}
} else {
CmdResult::new_state(Box::new(state))
}
}
Err(e) => CmdResult::DisplayError(format!("{}", e)),
}
}
Internal::help => {
let bang = input_invocation
.map(|inv| inv.bang)
.unwrap_or(internal_exec.bang);
if bang && cc.app.preview_panel.is_none() {
CmdResult::NewPanel {
state: Box::new(HelpState::new(self.tree_options(), screen, con)),
purpose: PanelPurpose::None,
direction: HDir::Right,
}
} else {
CmdResult::new_state(Box::new(
HelpState::new(self.tree_options(), screen, con)
))
}
}
Internal::mode_input => self.on_mode_verb(Mode::Input, con),
Internal::mode_command => self.on_mode_verb(Mode::Command, con),
Internal::open_leave => {
if let Some(selection) = self.selection() {
selection.to_opener(con)?
} else {
CmdResult::error("no selection to open")
}
}
Internal::open_preview => self.open_preview(None, false, cc),
Internal::preview_image => self.open_preview(Some(PreviewMode::Image), false, cc),
Internal::preview_text => self.open_preview(Some(PreviewMode::Text), false, cc),
Internal::preview_binary => self.open_preview(Some(PreviewMode::Hex), false, cc),
Internal::toggle_preview => self.open_preview(None, true, cc),
Internal::sort_by_count => self.with_new_options(
screen,
&|o| {
if o.sort == Sort::Count {
o.sort = Sort::None;
o.show_counts = false;
"*not sorting anymore*"
} else {
o.sort = Sort::Count;
o.show_counts = true;
"*now sorting by file count*"
}
},
bang,
con,
),
Internal::sort_by_date => self.with_new_options(
screen,
&|o| {
if o.sort == Sort::Date {
o.sort = Sort::None;
o.show_dates = false;
"*not sorting anymore*"
} else {
o.sort = Sort::Date;
o.show_dates = true;
"*now sorting by last modified date*"
}
},
bang,
con,
),
Internal::sort_by_size => self.with_new_options(
screen,
&|o| {
if o.sort == Sort::Size {
o.sort = Sort::None;
o.show_sizes = false;
"*not sorting anymore*"
} else {
o.sort = Sort::Size;
o.show_sizes = true;
o.show_root_fs = true;
"*now sorting files and directories by total size*"
}
},
bang,
con,
),
Internal::sort_by_type => self.with_new_options(
screen,
&|o| {
match o.sort {
Sort::TypeDirsFirst => {
o.sort = Sort::TypeDirsLast;
"*sorting by type, directories last*"
}
Sort::TypeDirsLast => {
o.sort = Sort::None;
"*not sorting anymore*"
}
_ => {
o.sort = Sort::TypeDirsFirst;
"*sorting by type, directories first*"
}
}
},
bang,
con,
),
Internal::sort_by_type_dirs_first => self.with_new_options(
screen,
&|o| {
if o.sort == Sort::TypeDirsFirst {
o.sort = Sort::None;
"*not sorting anymore*"
} else {
o.sort = Sort::TypeDirsFirst;
"*now sorting by type, directories first*"
}
},
bang,
con,
),
Internal::sort_by_type_dirs_last => self.with_new_options(
screen,
&|o| {
if o.sort == Sort::TypeDirsLast {
o.sort = Sort::None;
"*not sorting anymore*"
} else {
o.sort = Sort::TypeDirsLast;
"*now sorting by type, directories last*"
}
},
bang,
con,
),
Internal::no_sort => self.with_new_options(
screen,
&|o| {
if o.sort == Sort::None {
"*still not searching*"
} else {
o.sort = Sort::None;
"*not sorting anymore*"
}
},
bang,
con,
),
Internal::toggle_counts => {
self.with_new_options(
screen,
&|o| {
o.show_counts ^= true;
if o.show_counts {
"*displaying file counts*"
} else {
"*hiding file counts*"
}
},
bang,
con,
)
}
Internal::toggle_dates => {
self.with_new_options(
screen,
&|o| {
o.show_dates ^= true;
if o.show_dates {
"*displaying last modified dates*"
} else {
"*hiding last modified dates*"
}
},
bang,
con,
)
}
Internal::toggle_device_id => {
self.with_new_options(
screen,
&|o| {
o.show_device_id ^= true;
if o.show_device_id {
"*displaying device id*"
} else {
"*hiding device id*"
}
},
bang,
con,
)
}
Internal::toggle_files => {
self.with_new_options(
screen,
&|o| {
o.only_folders ^= true;
if o.only_folders {
"*displaying only directories*"
} else {
"*displaying both files and directories*"
}
},
bang,
con,
)
}
Internal::toggle_hidden => {
self.with_new_options(
screen,
&|o| {
o.show_hidden ^= true;
if o.show_hidden {
"h:**y** - *Hidden files displayed*"
} else {
"h:**n** - *Hidden files not displayed*"
}
},
bang,
con,
)
}
Internal::toggle_root_fs => {
self.with_new_options(
screen,
&|o| {
o.show_root_fs ^= true;
if o.show_root_fs {
"*displaying filesystem info for the tree's root directory*"
} else {
"*removing filesystem info*"
}
},
bang,
con,
)
}
Internal::toggle_git_ignore => {
self.with_new_options(
screen,
&|o| {
o.respect_git_ignore ^= true;
if o.respect_git_ignore {
"gi:**y** - *applying gitignore rules*"
} else {
"gi:**n** - *not applying gitignore rules*"
}
},
bang,
con,
)
}
Internal::toggle_git_file_info => {
self.with_new_options(
screen,
&|o| {
o.show_git_file_info ^= true;
if o.show_git_file_info {
"*displaying git info next to files*"
} else {
"*removing git file info*"
}
},
bang,
con,
)
}
Internal::toggle_git_status => {
self.with_new_options(
screen, &|o| {
if o.filter_by_git_status {
o.filter_by_git_status = false;
"*not filtering according to git status anymore*"
} else {
o.filter_by_git_status = true;
o.show_hidden = true;
"*only displaying new or modified files*"
}
}, bang, con
)
}
Internal::toggle_perm => {
self.with_new_options(
screen,
&|o| {
o.show_permissions ^= true;
if o.show_permissions {
"*displaying file permissions*"
} else {
"*removing file permissions*"
}
},
bang,
con,
)
}
Internal::toggle_sizes => self.with_new_options(
screen,
&|o| {
if o.show_sizes {
o.show_sizes = false;
o.show_root_fs = false;
"*removing sizes of files and directories*"
} else {
o.show_sizes = true;
o.show_root_fs = true;
"*now diplaying sizes of files and directories*"
}
},
bang,
con,
),
Internal::toggle_trim_root => {
self.with_new_options(
screen,
&|o| {
o.trim_root ^= true;
if o.trim_root {
"*now trimming root from excess files*"
} else {
"*not trimming root files anymore*"
}
},
bang,
con,
)
}
Internal::close_preview => {
if let Some(id) = cc.app.preview_panel {
CmdResult::ClosePanel {
validate_purpose: false,
panel_ref: PanelReference::Id(id),
}
} else {
CmdResult::Keep
}
}
Internal::panel_left | Internal::panel_left_no_open => {
CmdResult::HandleInApp(Internal::panel_left_no_open)
}
Internal::panel_right | Internal::panel_right_no_open => {
CmdResult::HandleInApp(Internal::panel_right_no_open)
}
Internal::toggle_second_tree => {
CmdResult::HandleInApp(Internal::toggle_second_tree)
}
Internal::clear_stage => {
app_state.stage.clear();
if let Some(panel_id) = cc.app.stage_panel {
CmdResult::ClosePanel {
validate_purpose: false,
panel_ref: PanelReference::Id(panel_id),
}
} else {
CmdResult::Keep
}
}
Internal::stage => self.stage(app_state, cc, con),
Internal::unstage => self.unstage(app_state, cc, con),
Internal::toggle_stage => self.toggle_stage(app_state, cc, con),
Internal::close_staging_area => {
if let Some(id) = cc.app.stage_panel {
CmdResult::ClosePanel {
validate_purpose: false,
panel_ref: PanelReference::Id(id),
}
} else {
CmdResult::Keep
}
}
Internal::open_staging_area => {
if cc.app.stage_panel.is_none() {
CmdResult::NewPanel {
state: Box::new(StageState::new(app_state, self.tree_options(), con)),
purpose: PanelPurpose::None,
direction: HDir::Right,
}
} else {
CmdResult::Keep
}
}
Internal::toggle_staging_area => {
if let Some(id) = cc.app.stage_panel {
CmdResult::ClosePanel {
validate_purpose: false,
panel_ref: PanelReference::Id(id),
}
} else {
CmdResult::NewPanel {
state: Box::new(StageState::new(app_state, self.tree_options(), con)),
purpose: PanelPurpose::None,
direction: HDir::Right,
}
}
}
Internal::set_syntax_theme => CmdResult::HandleInApp(Internal::set_syntax_theme),
Internal::print_path => print::print_paths(self.sel_info(app_state), con)?,
Internal::print_relative_path => print::print_relative_paths(self.sel_info(app_state), con)?,
Internal::refresh => CmdResult::RefreshState { clear_cache: true },
Internal::quit => CmdResult::Quit,
_ => CmdResult::Keep,
})
}
Trait Implementations§
source§impl PanelState for HelpState
impl PanelState for HelpState
fn get_type(&self) -> PanelStateType
fn set_mode(&mut self, mode: Mode)
fn get_mode(&self) -> Mode
fn selected_path(&self) -> Option<&Path>
fn tree_options(&self) -> TreeOptions
source§fn with_new_options(
&mut self,
_screen: Screen,
change_options: &dyn Fn(&mut TreeOptions) -> &'static str,
_in_new_panel: bool,
_con: &AppContext
) -> CmdResult
fn with_new_options(
&mut self,
_screen: Screen,
change_options: &dyn Fn(&mut TreeOptions) -> &'static str,
_in_new_panel: bool,
_con: &AppContext
) -> CmdResult
Build a cmdResult in response to a command being a change of
tree options. This may or not be a new state. Read more
fn selection(&self) -> Option<Selection<'_>>
fn refresh(&mut self, _screen: Screen, _con: &AppContext) -> Command
fn on_pattern(
&mut self,
pat: InputPattern,
_app_state: &AppState,
_con: &AppContext
) -> Result<CmdResult, ProgramError>
fn display(
&mut self,
w: &mut W,
disc: &DisplayContext<'_>
) -> Result<(), ProgramError>
source§fn on_internal(
&mut self,
w: &mut W,
internal_exec: &InternalExecution,
input_invocation: Option<&VerbInvocation>,
trigger_type: TriggerType<'_>,
app_state: &mut AppState,
cc: &CmdContext<'_>
) -> Result<CmdResult, ProgramError>
fn on_internal(
&mut self,
w: &mut W,
internal_exec: &InternalExecution,
input_invocation: Option<&VerbInvocation>,
trigger_type: TriggerType<'_>,
app_state: &mut AppState,
cc: &CmdContext<'_>
) -> Result<CmdResult, ProgramError>
execute the internal with the optional given invocation. Read more
source§fn clear_pending(&mut self)
fn clear_pending(&mut self)
called on start of on_command
fn on_click(
&mut self,
_x: u16,
_y: u16,
_screen: Screen,
_con: &AppContext
) -> Result<CmdResult, ProgramError>
fn on_double_click(
&mut self,
_x: u16,
_y: u16,
_screen: Screen,
_con: &AppContext
) -> Result<CmdResult, ProgramError>
fn on_mode_verb(&mut self, mode: Mode, con: &AppContext) -> CmdResult
source§fn on_internal_generic(
&mut self,
_w: &mut W,
internal_exec: &InternalExecution,
input_invocation: Option<&VerbInvocation>,
_trigger_type: TriggerType<'_>,
app_state: &mut AppState,
cc: &CmdContext<'_>
) -> Result<CmdResult, ProgramError>
fn on_internal_generic(
&mut self,
_w: &mut W,
internal_exec: &InternalExecution,
input_invocation: Option<&VerbInvocation>,
_trigger_type: TriggerType<'_>,
app_state: &mut AppState,
cc: &CmdContext<'_>
) -> Result<CmdResult, ProgramError>
a generic implementation of on_internal which may be
called by states when they don’t have a specific
behavior to execute
fn stage(
&self,
app_state: &mut AppState,
cc: &CmdContext<'_>,
con: &AppContext
) -> CmdResult
fn unstage(
&self,
app_state: &mut AppState,
cc: &CmdContext<'_>,
_con: &AppContext
) -> CmdResult
fn toggle_stage(
&self,
app_state: &mut AppState,
cc: &CmdContext<'_>,
con: &AppContext
) -> CmdResult
fn execute_verb(
&mut self,
w: &mut W,
verb: &Verb,
invocation: Option<&VerbInvocation>,
trigger_type: TriggerType<'_>,
app_state: &mut AppState,
cc: &CmdContext<'_>
) -> Result<CmdResult, ProgramError>
fn execute_external(
&mut self,
w: &mut W,
verb: &Verb,
external_execution: &ExternalExecution,
invocation: Option<&VerbInvocation>,
app_state: &mut AppState,
cc: &CmdContext<'_>
) -> Result<CmdResult, ProgramError>
fn execute_sequence(
&mut self,
_w: &mut W,
verb: &Verb,
seq_ex: &SequenceExecution,
invocation: Option<&VerbInvocation>,
app_state: &mut AppState,
_cc: &CmdContext<'_>
) -> Result<CmdResult, ProgramError>
source§fn on_command(
&mut self,
w: &mut W,
app_state: &mut AppState,
cc: &CmdContext<'_>
) -> Result<CmdResult, ProgramError>
fn on_command(
&mut self,
w: &mut W,
app_state: &mut AppState,
cc: &CmdContext<'_>
) -> Result<CmdResult, ProgramError>
change the state, does no rendering
source§fn open_preview(
&mut self,
prefered_mode: Option<PreviewMode>,
close_if_open: bool,
cc: &CmdContext<'_>
) -> CmdResult
fn open_preview(
&mut self,
prefered_mode: Option<PreviewMode>,
close_if_open: bool,
cc: &CmdContext<'_>
) -> CmdResult
return a cmdresult asking for the opening of a preview
source§fn tree_root(&self) -> Option<&Path>
fn tree_root(&self) -> Option<&Path>
must return None if the state doesn’t display a file tree
fn sel_info<'c>(&'c self, _app_state: &'c AppState) -> SelInfo<'c>
fn has_at_least_one_selection(&self, _app_state: &AppState) -> bool
fn do_pending_task(
&mut self,
_app_state: &mut AppState,
_screen: Screen,
_con: &AppContext,
_dam: &mut Dam
) -> Result<(), ProgramError>
fn get_pending_task(&self) -> Option<&'static str>
fn get_starting_input(&self) -> String
fn set_selected_path(&mut self, _path: PathBuf, _con: &AppContext)
source§fn no_verb_status(&self, _has_previous_state: bool, _con: &AppContext) -> Status
fn no_verb_status(&self, _has_previous_state: bool, _con: &AppContext) -> Status
return the status which should be used when there’s no verb edited