|
1 | 1 | use crossterm::event::{Event, KeyEvent, KeyEventKind}; |
2 | 2 | use serde::{Deserialize, Serialize}; |
3 | | -use std::fmt::{Display, Formatter}; |
4 | 3 | use strum::{EnumDiscriminants, EnumIter, EnumString, VariantArray}; |
5 | 4 |
|
6 | 5 | /// Which mouse button was pressed. |
@@ -93,7 +92,7 @@ impl Default for TextObject { |
93 | 92 | /// |
94 | 93 | /// Executed by `Reedline::run_edit_commands()` |
95 | 94 | #[non_exhaustive] |
96 | | -#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, EnumDiscriminants, EnumIter)] |
| 95 | +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, EnumDiscriminants)] |
97 | 96 | #[strum_discriminants(doc = "This is the auto generated discriminant type for [`EditCommand`]")] |
98 | 97 | #[strum_discriminants(derive(EnumIter, EnumString, VariantArray))] |
99 | 98 | #[strum_discriminants(strum(ascii_case_insensitive))] |
@@ -508,149 +507,6 @@ pub enum EditCommand { |
508 | 507 | }, |
509 | 508 | } |
510 | 509 |
|
511 | | -// FIXME: This implementation makes no sense to be here, and should be removed in a future version |
512 | | -// It was originally added for nushell to show all the available commands and their parameters to |
513 | | -// the users. Hence some are marked `Optional` and some have different parameter names. |
514 | | -// This is also very hard to keep in sync with nushell. |
515 | | -// So, recently its discriminants are exposed using the strum EnumDiscriminants, and downstream is |
516 | | -// expected to use that if they want to display the list of available commands to their users. |
517 | | -impl Display for EditCommand { |
518 | | - fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { |
519 | | - match self { |
520 | | - EditCommand::MoveToStart { .. } => write!(f, "MoveToStart Optional[select: <bool>]"), |
521 | | - EditCommand::MoveToLineStart { .. } => { |
522 | | - write!(f, "MoveToLineStart Optional[select: <bool>]") |
523 | | - } |
524 | | - EditCommand::MoveToLineNonBlankStart { .. } => { |
525 | | - write!(f, "MoveToLineNonBlankStart Optional[select: <bool>]") |
526 | | - } |
527 | | - EditCommand::MoveToEnd { .. } => write!(f, "MoveToEnd Optional[select: <bool>]"), |
528 | | - EditCommand::MoveToLineEnd { .. } => { |
529 | | - write!(f, "MoveToLineEnd Optional[select: <bool>]") |
530 | | - } |
531 | | - EditCommand::MoveLineUp { .. } => write!(f, "MoveLineUp Optional[select: <bool>]"), |
532 | | - EditCommand::MoveLineDown { .. } => write!(f, "MoveLineDown Optional[select: <bool>]"), |
533 | | - EditCommand::MoveLeft { .. } => write!(f, "MoveLeft Optional[select: <bool>]"), |
534 | | - EditCommand::MoveRight { .. } => write!(f, "MoveRight Optional[select: <bool>]"), |
535 | | - EditCommand::MoveWordLeft { .. } => write!(f, "MoveWordLeft Optional[select: <bool>]"), |
536 | | - EditCommand::MoveBigWordLeft { .. } => { |
537 | | - write!(f, "MoveBigWordLeft Optional[select: <bool>]") |
538 | | - } |
539 | | - EditCommand::MoveWordRight { .. } => { |
540 | | - write!(f, "MoveWordRight Optional[select: <bool>]") |
541 | | - } |
542 | | - EditCommand::MoveWordRightEnd { .. } => { |
543 | | - write!(f, "MoveWordRightEnd Optional[select: <bool>]") |
544 | | - } |
545 | | - EditCommand::MoveBigWordRightEnd { .. } => { |
546 | | - write!(f, "MoveBigWordRightEnd Optional[select: <bool>]") |
547 | | - } |
548 | | - EditCommand::MoveWordRightStart { .. } => { |
549 | | - write!(f, "MoveWordRightStart Optional[select: <bool>]") |
550 | | - } |
551 | | - EditCommand::MoveBigWordRightStart { .. } => { |
552 | | - write!(f, "MoveBigWordRightStart Optional[select: <bool>]") |
553 | | - } |
554 | | - EditCommand::MoveToPosition { .. } => { |
555 | | - write!(f, "MoveToPosition Value: <int>, Optional[select: <bool>]") |
556 | | - } |
557 | | - EditCommand::MoveLeftUntil { .. } => { |
558 | | - write!(f, "MoveLeftUntil Value: <char>, Optional[select: <bool>]") |
559 | | - } |
560 | | - EditCommand::MoveLeftBefore { .. } => { |
561 | | - write!(f, "MoveLeftBefore Value: <char>, Optional[select: <bool>]") |
562 | | - } |
563 | | - EditCommand::InsertChar(_) => write!(f, "InsertChar Value: <char>"), |
564 | | - EditCommand::InsertString(_) => write!(f, "InsertString Value: <string>"), |
565 | | - EditCommand::InsertNewline => write!(f, "InsertNewline"), |
566 | | - EditCommand::InsertNewlineAbove => write!(f, "InsertNewlineAbove"), |
567 | | - EditCommand::InsertNewlineBelow => write!(f, "InsertNewlineBelow"), |
568 | | - EditCommand::ReplaceChar(_) => write!(f, "ReplaceChar <char>"), |
569 | | - EditCommand::ReplaceChars(_, _) => write!(f, "ReplaceChars <int> <string>"), |
570 | | - EditCommand::Backspace => write!(f, "Backspace"), |
571 | | - EditCommand::Delete => write!(f, "Delete"), |
572 | | - EditCommand::CutChar => write!(f, "CutChar"), |
573 | | - EditCommand::BackspaceWord => write!(f, "BackspaceWord"), |
574 | | - EditCommand::DeleteWord => write!(f, "DeleteWord"), |
575 | | - EditCommand::Clear => write!(f, "Clear"), |
576 | | - EditCommand::ClearToLineEnd => write!(f, "ClearToLineEnd"), |
577 | | - EditCommand::Complete => write!(f, "Complete"), |
578 | | - EditCommand::CutCurrentLine => write!(f, "CutCurrentLine"), |
579 | | - EditCommand::CutFromStart => write!(f, "CutFromStart"), |
580 | | - EditCommand::CutFromStartLinewise { .. } => { |
581 | | - write!(f, "CutFromStartLinewise Value: <bool>") |
582 | | - } |
583 | | - EditCommand::CutFromLineStart => write!(f, "CutFromLineStart"), |
584 | | - EditCommand::CutFromLineNonBlankStart => write!(f, "CutFromLineNonBlankStart"), |
585 | | - EditCommand::CutToEnd => write!(f, "CutToEnd"), |
586 | | - EditCommand::CutToEndLinewise { .. } => { |
587 | | - write!(f, "CutToEndLinewise Value: <bool>") |
588 | | - } |
589 | | - EditCommand::CutToLineEnd => write!(f, "CutToLineEnd"), |
590 | | - EditCommand::KillLine => write!(f, "KillLine"), |
591 | | - EditCommand::CutWordLeft => write!(f, "CutWordLeft"), |
592 | | - EditCommand::CutBigWordLeft => write!(f, "CutBigWordLeft"), |
593 | | - EditCommand::CutWordRight => write!(f, "CutWordRight"), |
594 | | - EditCommand::CutBigWordRight => write!(f, "CutBigWordRight"), |
595 | | - EditCommand::CutWordRightToNext => write!(f, "CutWordRightToNext"), |
596 | | - EditCommand::CutBigWordRightToNext => write!(f, "CutBigWordRightToNext"), |
597 | | - EditCommand::PasteCutBufferBefore => write!(f, "PasteCutBufferBefore"), |
598 | | - EditCommand::PasteCutBufferAfter => write!(f, "PasteCutBufferAfter"), |
599 | | - EditCommand::UppercaseWord => write!(f, "UppercaseWord"), |
600 | | - EditCommand::LowercaseWord => write!(f, "LowercaseWord"), |
601 | | - EditCommand::SwitchcaseChar => write!(f, "SwitchcaseChar"), |
602 | | - EditCommand::CapitalizeChar => write!(f, "CapitalizeChar"), |
603 | | - EditCommand::SwapWords => write!(f, "SwapWords"), |
604 | | - EditCommand::SwapGraphemes => write!(f, "SwapGraphemes"), |
605 | | - EditCommand::Undo => write!(f, "Undo"), |
606 | | - EditCommand::Redo => write!(f, "Redo"), |
607 | | - EditCommand::CutRightUntil(_) => write!(f, "CutRightUntil Value: <char>"), |
608 | | - EditCommand::CutRightBefore(_) => write!(f, "CutRightBefore Value: <char>"), |
609 | | - EditCommand::MoveRightUntil { .. } => write!(f, "MoveRightUntil Value: <char>"), |
610 | | - EditCommand::MoveRightBefore { .. } => write!(f, "MoveRightBefore Value: <char>"), |
611 | | - EditCommand::CutLeftUntil(_) => write!(f, "CutLeftUntil Value: <char>"), |
612 | | - EditCommand::CutLeftBefore(_) => write!(f, "CutLeftBefore Value: <char>"), |
613 | | - EditCommand::SelectAll => write!(f, "SelectAll"), |
614 | | - EditCommand::CutSelection => write!(f, "CutSelection"), |
615 | | - EditCommand::CopySelection => write!(f, "CopySelection"), |
616 | | - EditCommand::Paste => write!(f, "Paste"), |
617 | | - EditCommand::CopyFromStart => write!(f, "CopyFromStart"), |
618 | | - EditCommand::CopyFromStartLinewise => write!(f, "CopyFromStartLinewise"), |
619 | | - EditCommand::CopyFromLineStart => write!(f, "CopyFromLineStart"), |
620 | | - EditCommand::CopyFromLineNonBlankStart => write!(f, "CopyFromLineNonBlankStart"), |
621 | | - EditCommand::CopyToEnd => write!(f, "CopyToEnd"), |
622 | | - EditCommand::CopyToEndLinewise => write!(f, "CopyToEndLinewise"), |
623 | | - EditCommand::CopyToLineEnd => write!(f, "CopyToLineEnd"), |
624 | | - EditCommand::CopyCurrentLine => write!(f, "CopyCurrentLine"), |
625 | | - EditCommand::CopyWordLeft => write!(f, "CopyWordLeft"), |
626 | | - EditCommand::CopyBigWordLeft => write!(f, "CopyBigWordLeft"), |
627 | | - EditCommand::CopyWordRight => write!(f, "CopyWordRight"), |
628 | | - EditCommand::CopyBigWordRight => write!(f, "CopyBigWordRight"), |
629 | | - EditCommand::CopyWordRightToNext => write!(f, "CopyWordRightToNext"), |
630 | | - EditCommand::CopyBigWordRightToNext => write!(f, "CopyBigWordRightToNext"), |
631 | | - EditCommand::CopyLeft => write!(f, "CopyLeft"), |
632 | | - EditCommand::CopyRight => write!(f, "CopyRight"), |
633 | | - EditCommand::CopyRightUntil(_) => write!(f, "CopyRightUntil Value: <char>"), |
634 | | - EditCommand::CopyRightBefore(_) => write!(f, "CopyRightBefore Value: <char>"), |
635 | | - EditCommand::CopyLeftUntil(_) => write!(f, "CopyLeftUntil Value: <char>"), |
636 | | - EditCommand::CopyLeftBefore(_) => write!(f, "CopyLeftBefore Value: <char>"), |
637 | | - EditCommand::SwapCursorAndAnchor => write!(f, "SwapCursorAndAnchor"), |
638 | | - #[cfg(feature = "system_clipboard")] |
639 | | - EditCommand::CutSelectionSystem => write!(f, "CutSelectionSystem"), |
640 | | - #[cfg(feature = "system_clipboard")] |
641 | | - EditCommand::CopySelectionSystem => write!(f, "CopySelectionSystem"), |
642 | | - #[cfg(feature = "system_clipboard")] |
643 | | - EditCommand::PasteSystem => write!(f, "PasteSystem"), |
644 | | - EditCommand::CutInsidePair { .. } => write!(f, "CutInsidePair Value: <char> <char>"), |
645 | | - EditCommand::CopyInsidePair { .. } => write!(f, "CopyInsidePair Value: <char> <char>"), |
646 | | - EditCommand::CutAroundPair { .. } => write!(f, "CutAroundPair Value: <char> <char>"), |
647 | | - EditCommand::CopyAroundPair { .. } => write!(f, "CopyAroundPair Value: <char> <char>"), |
648 | | - EditCommand::CutTextObject { .. } => write!(f, "CutTextObject Value: <TextObject>"), |
649 | | - EditCommand::CopyTextObject { .. } => write!(f, "CopyTextObject Value: <TextObject>"), |
650 | | - } |
651 | | - } |
652 | | -} |
653 | | - |
654 | 510 | impl EditCommand { |
655 | 511 | /// Determine if a certain operation should be undoable |
656 | 512 | /// or if the operations should be coalesced for undoing |
@@ -835,7 +691,7 @@ impl UndoBehavior { |
835 | 691 | } |
836 | 692 |
|
837 | 693 | /// Reedline supported actions. |
838 | | -#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug, EnumDiscriminants, EnumIter)] |
| 694 | +#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug, EnumDiscriminants)] |
839 | 695 | #[strum_discriminants(doc = "This is the auto generated discriminant type for [`ReedlineEvent`]")] |
840 | 696 | #[strum_discriminants(derive(EnumIter, EnumString, VariantArray))] |
841 | 697 | #[strum_discriminants(strum(ascii_case_insensitive))] |
@@ -983,64 +839,6 @@ pub enum ReedlineEvent { |
983 | 839 | ViChangeMode(String), |
984 | 840 | } |
985 | 841 |
|
986 | | -// FIXME: This implementation makes no sense to be here, and should be removed in a future version |
987 | | -// It was originally added for nushell to show all the available commands and their parameters to |
988 | | -// the users. |
989 | | -// This is also very hard to keep in sync with nushell. |
990 | | -// So, recently its discriminants are exposed using the strum EnumDiscriminants, and downstream is |
991 | | -// expected to use that if they want to display the list of available commands to their users. |
992 | | -impl Display for ReedlineEvent { |
993 | | - fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { |
994 | | - match self { |
995 | | - ReedlineEvent::None => write!(f, "None"), |
996 | | - ReedlineEvent::HistoryHintComplete => write!(f, "HistoryHintComplete"), |
997 | | - ReedlineEvent::HistoryHintWordComplete => write!(f, "HistoryHintWordComplete"), |
998 | | - ReedlineEvent::CtrlD => write!(f, "CtrlD"), |
999 | | - ReedlineEvent::CtrlC => write!(f, "CtrlC"), |
1000 | | - ReedlineEvent::ClearScreen => write!(f, "ClearScreen"), |
1001 | | - ReedlineEvent::ClearScrollback => write!(f, "ClearScrollback"), |
1002 | | - ReedlineEvent::Enter => write!(f, "Enter"), |
1003 | | - ReedlineEvent::Submit => write!(f, "Submit"), |
1004 | | - ReedlineEvent::SubmitOrNewline => write!(f, "SubmitOrNewline"), |
1005 | | - ReedlineEvent::Esc => write!(f, "Esc"), |
1006 | | - ReedlineEvent::Mouse { |
1007 | | - column, |
1008 | | - row, |
1009 | | - button, |
1010 | | - } => write!(f, "Mouse({}, {}, {:?})", column, row, button), |
1011 | | - ReedlineEvent::Resize(_, _) => write!(f, "Resize <int> <int>"), |
1012 | | - ReedlineEvent::Edit(_) => write!( |
1013 | | - f, |
1014 | | - "Edit: <EditCommand> or Edit: <EditCommand> value: <string>" |
1015 | | - ), |
1016 | | - ReedlineEvent::Repaint => write!(f, "Repaint"), |
1017 | | - ReedlineEvent::PreviousHistory => write!(f, "PreviousHistory"), |
1018 | | - ReedlineEvent::Up => write!(f, "Up"), |
1019 | | - ReedlineEvent::Down => write!(f, "Down"), |
1020 | | - ReedlineEvent::ToStart => write!(f, "ToStart"), |
1021 | | - ReedlineEvent::ToEnd => write!(f, "ToEnd"), |
1022 | | - ReedlineEvent::Right => write!(f, "Right"), |
1023 | | - ReedlineEvent::Left => write!(f, "Left"), |
1024 | | - ReedlineEvent::NextHistory => write!(f, "NextHistory"), |
1025 | | - ReedlineEvent::SearchHistory => write!(f, "SearchHistory"), |
1026 | | - ReedlineEvent::Multiple(_) => write!(f, "Multiple[ {{ ReedLineEvents, }} ]"), |
1027 | | - ReedlineEvent::UntilFound(_) => write!(f, "UntilFound [ {{ ReedLineEvents, }} ]"), |
1028 | | - ReedlineEvent::Menu(_) => write!(f, "Menu Name: <string>"), |
1029 | | - ReedlineEvent::MenuNext => write!(f, "MenuNext"), |
1030 | | - ReedlineEvent::MenuPrevious => write!(f, "MenuPrevious"), |
1031 | | - ReedlineEvent::MenuUp => write!(f, "MenuUp"), |
1032 | | - ReedlineEvent::MenuDown => write!(f, "MenuDown"), |
1033 | | - ReedlineEvent::MenuLeft => write!(f, "MenuLeft"), |
1034 | | - ReedlineEvent::MenuRight => write!(f, "MenuRight"), |
1035 | | - ReedlineEvent::MenuPageNext => write!(f, "MenuPageNext"), |
1036 | | - ReedlineEvent::MenuPagePrevious => write!(f, "MenuPagePrevious"), |
1037 | | - ReedlineEvent::ExecuteHostCommand(_) => write!(f, "ExecuteHostCommand"), |
1038 | | - ReedlineEvent::OpenEditor => write!(f, "OpenEditor"), |
1039 | | - ReedlineEvent::ViChangeMode(_) => write!(f, "ViChangeMode mode: <string>"), |
1040 | | - } |
1041 | | - } |
1042 | | -} |
1043 | | - |
1044 | 842 | pub enum EventStatus { |
1045 | 843 | Handled, |
1046 | 844 | Inapplicable, |
|
0 commit comments