From a272d3df16df67db0cd41df517b7d0379116ccee Mon Sep 17 00:00:00 2001 From: John Higgins Date: Fri, 9 Sep 2022 17:04:09 -0700 Subject: [PATCH 01/14] Added -S flag for truncating long lines --- src/bin/bat/app.rs | 23 ++++++++++++++--------- src/bin/bat/clap_app.rs | 7 +++++++ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 7bab26c3..b52aa265 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -161,17 +161,22 @@ impl App { }), show_nonprintable: self.matches.get_flag("show-all"), wrapping_mode: if self.interactive_output || maybe_term_width.is_some() { - match self.matches.get_one::("wrap").map(|s| s.as_str()) { - Some("character") => WrappingMode::Character, - Some("never") => WrappingMode::NoWrapping(true), - Some("auto") | None => { - if style_components.plain() { - WrappingMode::NoWrapping(false) - } else { - WrappingMode::Character + if !self.matches.contains_id("chop-long-lines") { + match self.matches.get_one::("wrap").map(|s| s.as_str()) { + Some("character") => WrappingMode::Character, + Some("never") => WrappingMode::NoWrapping(true), + Some("auto") | None => { + if style_components.plain() { + WrappingMode::NoWrapping(false) + } else { + WrappingMode::Character + } } + _ => unreachable!("other values for --wrap are not allowed"), } - _ => unreachable!("other values for --wrap are not allowed"), + } + else { + WrappingMode::NoWrapping(true) } } else { // We don't have the tty width when piping to another program. diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index f96e9e98..426f6171 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -201,6 +201,13 @@ pub fn build_app(interactive_output: bool) -> Command<'static> { The '--terminal-width' option can be used in addition to \ control the output width."), ) + .arg( + Arg::new("chop-long-lines") + .long("chop-long-lines") + .short('S') + .takes_value(false) + .help("Truncate all lines longer than screen width. Alias for '--wrap=never'."), + ) .arg( Arg::new("terminal-width") .long("terminal-width") From 2af54dbacda66a34155edfd3cdf6552de8573c4b Mon Sep 17 00:00:00 2001 From: John Higgins Date: Fri, 9 Sep 2022 22:26:53 -0700 Subject: [PATCH 02/14] Fixed else statement with `cargo fmt` --- src/bin/bat/app.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index b52aa265..75e5a063 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -174,8 +174,7 @@ impl App { } _ => unreachable!("other values for --wrap are not allowed"), } - } - else { + } else { WrappingMode::NoWrapping(true) } } else { From 06b403aa92a36060e9595abfa6cfac1a77d0e1a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= Date: Wed, 14 Sep 2022 22:36:05 +0200 Subject: [PATCH 03/14] Add syntax support for Ada MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add submodule with sublime syntax. Add corresponding tests for both Ada (in adb/ads) and for the companion tool gpr. fixes #1300 Signed-off-by: Marc Poulhiès --- .gitmodules | 3 + assets/syntaxes/02_Extra/Ada | 1 + tests/syntax-tests/highlighted/Ada/click.adb | 308 +++++++++++++++++ tests/syntax-tests/highlighted/Ada/click.ads | 339 +++++++++++++++++++ tests/syntax-tests/highlighted/Ada/click.gpr | 29 ++ tests/syntax-tests/source/Ada/LICENSE.md | 23 ++ tests/syntax-tests/source/Ada/click.adb | 308 +++++++++++++++++ tests/syntax-tests/source/Ada/click.ads | 339 +++++++++++++++++++ tests/syntax-tests/source/Ada/click.gpr | 29 ++ 9 files changed, 1379 insertions(+) create mode 160000 assets/syntaxes/02_Extra/Ada create mode 100644 tests/syntax-tests/highlighted/Ada/click.adb create mode 100644 tests/syntax-tests/highlighted/Ada/click.ads create mode 100644 tests/syntax-tests/highlighted/Ada/click.gpr create mode 100644 tests/syntax-tests/source/Ada/LICENSE.md create mode 100644 tests/syntax-tests/source/Ada/click.adb create mode 100644 tests/syntax-tests/source/Ada/click.ads create mode 100644 tests/syntax-tests/source/Ada/click.gpr diff --git a/.gitmodules b/.gitmodules index 156f4206..ea770862 100644 --- a/.gitmodules +++ b/.gitmodules @@ -244,3 +244,6 @@ url = https://github.com/victor-gp/cmd-help-sublime-syntax.git branch = main shallow = true +[submodule "assets/syntaxes/02_Extra/Ada"] + path = assets/syntaxes/02_Extra/Ada + url = https://github.com/wiremoons/ada-sublime-syntax diff --git a/assets/syntaxes/02_Extra/Ada b/assets/syntaxes/02_Extra/Ada new file mode 160000 index 00000000..e2b8fd51 --- /dev/null +++ b/assets/syntaxes/02_Extra/Ada @@ -0,0 +1 @@ +Subproject commit e2b8fd51756e0cc42172c1c3405832ce9c19b6b6 diff --git a/tests/syntax-tests/highlighted/Ada/click.adb b/tests/syntax-tests/highlighted/Ada/click.adb new file mode 100644 index 00000000..2aeb0410 --- /dev/null +++ b/tests/syntax-tests/highlighted/Ada/click.adb @@ -0,0 +1,308 @@ +with Chests.Ring_Buffers; +with USB.Device.HID.Keyboard; + +package body Click is + ---------------- + -- DEBOUNCE -- + ---------------- + + -- Ideally, in a separate package. + + -- should be [], but not fixed yet in GCC 11. + Current_Status : Key_Matrix := [others => [others => False]]; + New_Status : Key_Matrix := [others => [others => False]]; + Since : Natural := 0; + -- Nb_Bounce : Natural := 5; + + function Update (NewS : Key_Matrix) return Boolean is + begin + -- The new state is the same as the current stable state => Do nothing. + if Current_Status = NewS then + Since := 0; + return False; + end if; + + if New_Status /= NewS then + -- The new state differs from the previous + -- new state (bouncing) => reset + New_Status := NewS; + Since := 1; + else + -- The new state hasn't changed since last + -- update => towards stabilization. + Since := Since + 1; + end if; + + if Since > Nb_Bounce then + declare + Tmp : constant Key_Matrix := Current_Status; + begin + -- New state has been stable enough. + -- Latch it and notifies caller. + Current_Status := New_Status; + New_Status := Tmp; + Since := 0; + end; + + return True; + else + -- Not there yet + return False; + end if; + end Update; + + procedure Get_Matrix; + -- Could use := []; but GNAT 12 has a bug (fixed in upcoming 13) + Read_Status : Key_Matrix := [others => [others => False]]; + + function Get_Events return Events is + Num_Evt : Natural := 0; + New_S : Key_Matrix renames Read_Status; + begin + Get_Matrix; + if Update (New_S) then + for I in Current_Status'Range (1) loop + for J in Current_Status'Range (2) loop + if (not New_Status (I, J) and then Current_Status (I, J)) + or else (New_Status (I, J) and then not Current_Status (I, J)) + then + Num_Evt := Num_Evt + 1; + end if; + end loop; + end loop; + + declare + Evts : Events (Natural range 1 .. Num_Evt); + Cursor : Natural range 1 .. Num_Evt + 1 := 1; + begin + for I in Current_Status'Range (1) loop + for J in Current_Status'Range (2) loop + if not New_Status (I, J) + and then Current_Status (I, J) + then + -- Pressing I, J + Evts (Cursor) := [ + Evt => Press, + Col => I, + Row => J + ]; + Cursor := Cursor + 1; + elsif New_Status (I, J) + and then not Current_Status (I, J) + then + -- Release I, J + Evts (Cursor) := [ + Evt => Release, + Col => I, + Row => J + ]; + Cursor := Cursor + 1; + end if; + end loop; + end loop; + return Evts; + end; + end if; + + return []; + end Get_Events; + + procedure Get_Matrix is -- return Key_Matrix is + begin + for Row in Keys.Rows'Range loop + Keys.Rows (Row).Clear; + + for Col in Keys.Cols'Range loop + Read_Status (Col, Row) := not Keys.Cols (Col).Set; + end loop; + Keys.Rows (Row).Set; + end loop; + end Get_Matrix; + + -- End of DEBOUNCE + + -------------- + -- Layout -- + -------------- + + package Events_Ring_Buffers is new Chests.Ring_Buffers + (Element_Type => Event, + Capacity => 16); + + Queued_Events : Events_Ring_Buffers.Ring_Buffer; + + type Statet is (Normal_Key, Layer_Mod, None); + type State is record + Typ : Statet; + Code : Key_Code_T; + Layer_Value : Natural; + -- Col : ColR; + -- Row : RowR; + end record; + + type State_Array is array (ColR, RowR) of State; + States : State_Array := [others => [others => (Typ => None, Code => No, Layer_Value => 0)]]; + + function Kw (Code : Key_Code_T) return Action is + begin + return (T => Key, C => Code, L => 0); + end Kw; + + function Lw (V : Natural) return Action is + begin + return (T => Layer, C => No, L => V); + end Lw; + + -- FIXME: hardcoded max number of events + subtype Events_Range is Natural range 0 .. 60; + type Array_Of_Reg_Events is array (Events_Range) of Event; + + Stamp : Natural := 0; + + procedure Register_Events (L : Layout; Es : Events) is + begin + Stamp := Stamp + 1; + + Log ("Reg events: " & Stamp'Image); + Log (Es'Length'Image); + for E of Es loop + declare + begin + if Events_Ring_Buffers.Is_Full (Queued_Events) then + raise Program_Error; + end if; + + Events_Ring_Buffers.Append (Queued_Events, E); + end; + -- Log ("Reg'ed events:" & Events_Mark'Image); + Log ("Reg'ed events:" & Events_Ring_Buffers.Length (Queued_Events)'Image); + end loop; + end Register_Events; + + procedure Release (Col: Colr; Row: Rowr) is + begin + if States (Col, Row).Typ = None then + raise Program_Error; + end if; + States (Col, Row) := (Typ => None, Code => No, Layer_Value => 0); + end Release; + + function Get_Current_Layer return Natural is + L : Natural := 0; + begin + for S of States loop + if S.Typ = Layer_Mod then + L := L + S.Layer_Value; + end if; + end loop; + + return L; + end Get_Current_Layer; + + -- Tick the event. + -- Returns TRUE if it needs to stay in the queued events + -- FALSE if the event has been consumed. + + function Tick (L: Layout; E : in out Event) return Boolean is + Current_Layer : Natural := Get_Current_Layer; + A : Action renames L (Current_Layer, E.Row, E.Col); + begin + case E.Evt is + when Press => + case A.T is + when Key => + States (E.Col, E.Row) := + (Typ => Normal_Key, + Code => A.C, + Layer_Value => 0); + when Layer => + States (E.Col, E.Row) := (Typ => Layer_Mod, Layer_Value => A.L, Code => No); + when others => + raise Program_Error; + end case; + + when Release => + Release (E.Col, E.Row); + end case; + return False; + end Tick; + + Last_Was_Empty_Log : Boolean := False; + + procedure Tick (L : Layout) is + begin + for I in 1 .. Events_Ring_Buffers.Length(Queued_Events) loop + declare + E : Event := Events_Ring_Buffers.Last_Element (Queued_Events); + begin + Events_Ring_Buffers.Delete_Last (Queued_Events); + if Tick (L, E) then + Events_Ring_Buffers.Prepend (Queued_Events, E); + end if; + end; + end loop; + if not Last_Was_Empty_Log or else Events_Ring_Buffers.Length(Queued_Events) /= 0 then + Log ("End Tick layout, events: " & Events_Ring_Buffers.Length(Queued_Events)'Image); + Last_Was_Empty_Log := Events_Ring_Buffers.Length(Queued_Events) = 0; + end if; + end Tick; + + function Get_Key_Codes return Key_Codes_T is + Codes : Key_Codes_T (0 .. 10); + Wm: Natural := 0; + begin + for S of States loop + if S.Typ = Normal_Key and then + (S.Code < LCtrl or else S.Code > RGui) + then + Codes (Wm) := S.Code; + Wm := Wm + 1; + end if; + end loop; + + if Wm = 0 then + return []; + else + return Codes (0 .. Wm - 1); + end if; + end Get_Key_Codes; + + function Get_Modifiers return Key_Modifiers is + use USB.Device.HID.Keyboard; + KM : Key_Modifiers (1..8); + I : Natural := 0; + begin + for S of States loop + if S.Typ = Normal_Key then + I := I + 1; + case S.Code is + when LCtrl => + KM(I) := Ctrl_Left; + when RCtrl => + KM(I) := Ctrl_Right; + when LShift => + KM(I) := Shift_Left; + when RShift => + KM(I) := Shift_Right; + when LAlt => + KM(I) := Alt_Left; + when RAlt => + KM(I) := Alt_Right; + when LGui => + KM(I) := Meta_Left; + when RGui => + KM(I) := Meta_Right; + when others => + I := I - 1; + end case; + end if; + end loop; + return KM (1..I); + end Get_Modifiers; + + procedure Init is + begin + Events_Ring_Buffers.Clear (Queued_Events); + end Init; + +end Click; diff --git a/tests/syntax-tests/highlighted/Ada/click.ads b/tests/syntax-tests/highlighted/Ada/click.ads new file mode 100644 index 00000000..412735ae --- /dev/null +++ b/tests/syntax-tests/highlighted/Ada/click.ads @@ -0,0 +1,339 @@ +with HAL.GPIO; +with USB.Device.HID.Keyboard; + +generic + Nb_Bounce : Natural; + type ColR is (<>); + type RowR is (<>); + + type GPIOP is new HAL.GPIO.GPIO_Point with private; + + type Cols_T is array (ColR) of GPIOP; + type Rows_T is array (RowR) of GPIOP; + + Cols : Cols_T; + Rows : Rows_T; + Num_Layers : Natural; + + with procedure Log (S : String; L : Integer := 1; Deindent : Integer := 0); +package Click is + + type Keys_T is record + Cols : Cols_T; + Rows : Rows_T; + end record; + + Keys : Keys_T := + (Rows => Rows, Cols => Cols); + + type Key_Matrix is array (ColR, RowR) of Boolean; + + -------------------------- + -- Events & Debouncing -- + -------------------------- + + MaxEvents : constant Positive := 20; + + type EventT is (Press, Release); + type Event is record + Evt : EventT; + Col : ColR; + Row : RowR; + end record; + + type Events is array (Natural range <>) of Event; + + function Get_Events return Events; + function Update (NewS : Key_Matrix) return Boolean; + + ------------- + -- Layout -- + ------------- + --------------- + -- Keycodes -- + --------------- + + -- Keycodes copy/pasted from the excelent Keyberon Rust firmware: + -- https://github.com/TeXitoi/keyberon/ + + type Key_Code_T is + ( + -- The "no" key, a placeholder to express nothing. + No, -- = 0x00, + -- / Error if too much keys are pressed at + -- the same time. + ErrorRollOver, + -- / The POST fail error. + PostFail, + -- / An undefined error occured. + ErrorUndefined, + -- / `a` and `A`. + A, + B, + C, + D, + E, + F, + G, + H, + I, + J, + K, + L, + M, -- 0x10 + N, + O, + P, + Q, + R, + S, + T, + U, + V, + W, + X, + Y, + Z, + -- `1` and `!`. + Kb1, + -- `2` and `@`. + Kb2, + -- `3` and `#`. + Kb3, -- 0x20 + -- / `4` and `$`. + Kb4, + -- `5` and `%`. + Kb5, + -- `6` and `^`. + Kb6, + -- `7` and `&`. + Kb7, + -- `8` and `*`. + Kb8, + -- `9` and `(`. + Kb9, + -- `0` and `)`. + Kb0, + Enter, + Escape, + BSpace, + Tab, + Space, + -- `-` and `_`. + Minus, + -- `=` and `+`. + Equal, + -- `[` and `{`. + LBracket, + -- `]` and `}`. + RBracket, -- 0x30 + -- / `\` and `|`. + Bslash, + -- Non-US `#` and `~` (Typically near the Enter key). + NonUsHash, + -- `;` and `:`. + SColon, + -- `'` and `"`. + Quote, + -- How to have ` as code? + -- \` and `~`. + Grave, + -- `,` and `<`. + Comma, + -- `.` and `>`. + Dot, + -- `/` and `?`. + Slash, + CapsLock, + F1, + F2, + F3, + F4, + F5, + F6, + F7, -- 0x40 + F8, + F9, + F10, + F11, + F12, + PScreen, + ScrollLock, + Pause, + Insert, + Home, + PgUp, + Delete, + Endd, + PgDown, + Right, + Left, -- 0x50 + Down, + Up, + NumLock, + -- Keypad `/` + KpSlash, + -- Keypad `*` + KpAsterisk, + -- Keypad `-`. + KpMinus, + -- Keypad `+`. + KpPlus, + -- Keypad enter. + KpEnter, + -- Keypad 1. + Kp1, + Kp2, + Kp3, + Kp4, + Kp5, + Kp6, + Kp7, + Kp8, -- 0x60 + Kp9, + Kp0, + KpDot, + -- Non-US `\` and `|` (Typically near the Left-Shift key) + NonUsBslash, + Application, -- 0x65 + -- / not a key, used for errors + Power, + -- Keypad `=`. + KpEqual, + F13, + F14, + F15, + F16, + F17, + F18, + F19, + F20, + F21, -- 0x70 + F22, + F23, + F24, + Execute, + Help, + Menu, + Selectt, + Stop, + Again, + Undo, + Cut, + Copy, + Paste, + Find, + Mute, + VolUp, -- 0x80 + VolDown, + -- Deprecated. + LockingCapsLock, + -- Deprecated. + LockingNumLock, + -- Deprecated. + LockingScrollLock, + -- / Keypad `,`, also used for the + -- brazilian keypad period (.) key. + KpComma, + -- Used on AS/400 keyboard + KpEqualSign, + Intl1, + Intl2, + Intl3, + Intl4, + Intl5, + Intl6, + Intl7, + Intl8, + Intl9, + Lang1, -- 0x90 + Lang2, + Lang3, + Lang4, + Lang5, + Lang6, + Lang7, + Lang8, + Lang9, + AltErase, + SysReq, + Cancel, + Clear, + Prior, + Returnn, + Separator, + Outt, -- 0xA0 + Oper, + ClearAgain, + CrSel, + ExSel, + + -- According to QMK, 0xA5-0xDF are not + -- usable on modern keyboards + + -- Modifiers + -- Left Control. + LCtrl, -- = 0xE0, + -- / Left Shift. + LShift, + -- Left Alt. + LAlt, + -- Left GUI (the Windows key). + LGui, + -- Right Control. + RCtrl, + -- Right Shift. + RShift, + -- Right Alt (or Alt Gr).  + RAlt, + -- Right GUI (the Windows key). + RGui, -- 0xE7 + + -- Unofficial + MediaPlayPause, -- 0xE8, + MediaStopCD, + MediaPreviousSong, + MediaNextSong, + MediaEjectCD, + MediaVolUp, + MediaVolDown, + MediaMute, + MediaWWW, -- 0xF0 + MediaBack, + MediaForward, + MediaStop, + MediaFind, + MediaScrollUp, + MediaScrollDown, + MediaEdit, + MediaSleep, + MediaCoffee, + MediaRefresh, + MediaCalc -- 0xFB + ); + + type Action_Type is (Key, No_Op, Trans, Layer, Multiple_Actions); + + -- Should be a discriminated type + type Action is record + T : Action_Type; -- hould be the discriminant + C : Key_Code_T; + L : Natural; + end record; + + function Kw (Code : Key_Code_T) return Action; + function Lw (V : Natural) return Action; + + type Key_Modifiers is array (Natural range <>) of USB.Device.HID.Keyboard.Modifiers; + + type Key_Codes_T is array (Natural range <>) of Key_Code_T; + + subtype Ac is Action; + type Layout is array (0 .. Num_Layers - 1, RowR, ColR) of Action; + procedure Register_Events (L : Layout; Es : Events); + procedure Tick (L : Layout); + + function Get_Key_Codes return Key_Codes_T; + function Get_Modifiers return Key_Modifiers; + procedure Init; +end Click; diff --git a/tests/syntax-tests/highlighted/Ada/click.gpr b/tests/syntax-tests/highlighted/Ada/click.gpr new file mode 100644 index 00000000..fb7a758d --- /dev/null +++ b/tests/syntax-tests/highlighted/Ada/click.gpr @@ -0,0 +1,29 @@ +with "config/click_config.gpr"; +project Click is + + for Library_Name use "Click"; + for Library_Version use Project'Library_Name & ".so." & Click_Config.Crate_Version; + + for Source_Dirs use ("src/", "config/"); + for Object_Dir use "obj/" & Click_Config.Build_Profile; + for Create_Missing_Dirs use "True"; + for Library_Dir use "lib"; + + type Library_Type_Type is ("relocatable", "static", "static-pic"); + Library_Type : Library_Type_Type := + external ("CLICK_LIBRARY_TYPE", external ("LIBRARY_TYPE", "static")); + for Library_Kind use Library_Type; + + package Compiler is + for Default_Switches ("Ada") use Click_Config.Ada_Compiler_Switches & ("-gnatX", "-gnat2022"); + end Compiler; + + package Binder is + for Switches ("Ada") use ("-Es"); -- Symbolic traceback + end Binder; + + package Install is + for Artifacts (".") use ("share"); + end Install; + +end Click; diff --git a/tests/syntax-tests/source/Ada/LICENSE.md b/tests/syntax-tests/source/Ada/LICENSE.md new file mode 100644 index 00000000..0700ff35 --- /dev/null +++ b/tests/syntax-tests/source/Ada/LICENSE.md @@ -0,0 +1,23 @@ +The files `click.adb`, `click.ads` and `click.gpr` have been added from https://github.com/dkm/click under the following license: + +MIT License + +Copyright (c) 2022 Marc Poulhiès + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/tests/syntax-tests/source/Ada/click.adb b/tests/syntax-tests/source/Ada/click.adb new file mode 100644 index 00000000..c525beda --- /dev/null +++ b/tests/syntax-tests/source/Ada/click.adb @@ -0,0 +1,308 @@ +with Chests.Ring_Buffers; +with USB.Device.HID.Keyboard; + +package body Click is + ---------------- + -- DEBOUNCE -- + ---------------- + + -- Ideally, in a separate package. + + -- should be [], but not fixed yet in GCC 11. + Current_Status : Key_Matrix := [others => [others => False]]; + New_Status : Key_Matrix := [others => [others => False]]; + Since : Natural := 0; + -- Nb_Bounce : Natural := 5; + + function Update (NewS : Key_Matrix) return Boolean is + begin + -- The new state is the same as the current stable state => Do nothing. + if Current_Status = NewS then + Since := 0; + return False; + end if; + + if New_Status /= NewS then + -- The new state differs from the previous + -- new state (bouncing) => reset + New_Status := NewS; + Since := 1; + else + -- The new state hasn't changed since last + -- update => towards stabilization. + Since := Since + 1; + end if; + + if Since > Nb_Bounce then + declare + Tmp : constant Key_Matrix := Current_Status; + begin + -- New state has been stable enough. + -- Latch it and notifies caller. + Current_Status := New_Status; + New_Status := Tmp; + Since := 0; + end; + + return True; + else + -- Not there yet + return False; + end if; + end Update; + + procedure Get_Matrix; + -- Could use := []; but GNAT 12 has a bug (fixed in upcoming 13) + Read_Status : Key_Matrix := [others => [others => False]]; + + function Get_Events return Events is + Num_Evt : Natural := 0; + New_S : Key_Matrix renames Read_Status; + begin + Get_Matrix; + if Update (New_S) then + for I in Current_Status'Range (1) loop + for J in Current_Status'Range (2) loop + if (not New_Status (I, J) and then Current_Status (I, J)) + or else (New_Status (I, J) and then not Current_Status (I, J)) + then + Num_Evt := Num_Evt + 1; + end if; + end loop; + end loop; + + declare + Evts : Events (Natural range 1 .. Num_Evt); + Cursor : Natural range 1 .. Num_Evt + 1 := 1; + begin + for I in Current_Status'Range (1) loop + for J in Current_Status'Range (2) loop + if not New_Status (I, J) + and then Current_Status (I, J) + then + -- Pressing I, J + Evts (Cursor) := [ + Evt => Press, + Col => I, + Row => J + ]; + Cursor := Cursor + 1; + elsif New_Status (I, J) + and then not Current_Status (I, J) + then + -- Release I, J + Evts (Cursor) := [ + Evt => Release, + Col => I, + Row => J + ]; + Cursor := Cursor + 1; + end if; + end loop; + end loop; + return Evts; + end; + end if; + + return []; + end Get_Events; + + procedure Get_Matrix is -- return Key_Matrix is + begin + for Row in Keys.Rows'Range loop + Keys.Rows (Row).Clear; + + for Col in Keys.Cols'Range loop + Read_Status (Col, Row) := not Keys.Cols (Col).Set; + end loop; + Keys.Rows (Row).Set; + end loop; + end Get_Matrix; + + -- End of DEBOUNCE + + -------------- + -- Layout -- + -------------- + + package Events_Ring_Buffers is new Chests.Ring_Buffers + (Element_Type => Event, + Capacity => 16); + + Queued_Events : Events_Ring_Buffers.Ring_Buffer; + + type Statet is (Normal_Key, Layer_Mod, None); + type State is record + Typ : Statet; + Code : Key_Code_T; + Layer_Value : Natural; + -- Col : ColR; + -- Row : RowR; + end record; + + type State_Array is array (ColR, RowR) of State; + States : State_Array := [others => [others => (Typ => None, Code => No, Layer_Value => 0)]]; + + function Kw (Code : Key_Code_T) return Action is + begin + return (T => Key, C => Code, L => 0); + end Kw; + + function Lw (V : Natural) return Action is + begin + return (T => Layer, C => No, L => V); + end Lw; + + -- FIXME: hardcoded max number of events + subtype Events_Range is Natural range 0 .. 60; + type Array_Of_Reg_Events is array (Events_Range) of Event; + + Stamp : Natural := 0; + + procedure Register_Events (L : Layout; Es : Events) is + begin + Stamp := Stamp + 1; + + Log ("Reg events: " & Stamp'Image); + Log (Es'Length'Image); + for E of Es loop + declare + begin + if Events_Ring_Buffers.Is_Full (Queued_Events) then + raise Program_Error; + end if; + + Events_Ring_Buffers.Append (Queued_Events, E); + end; + -- Log ("Reg'ed events:" & Events_Mark'Image); + Log ("Reg'ed events:" & Events_Ring_Buffers.Length (Queued_Events)'Image); + end loop; + end Register_Events; + + procedure Release (Col: Colr; Row: Rowr) is + begin + if States (Col, Row).Typ = None then + raise Program_Error; + end if; + States (Col, Row) := (Typ => None, Code => No, Layer_Value => 0); + end Release; + + function Get_Current_Layer return Natural is + L : Natural := 0; + begin + for S of States loop + if S.Typ = Layer_Mod then + L := L + S.Layer_Value; + end if; + end loop; + + return L; + end Get_Current_Layer; + + -- Tick the event. + -- Returns TRUE if it needs to stay in the queued events + -- FALSE if the event has been consumed. + + function Tick (L: Layout; E : in out Event) return Boolean is + Current_Layer : Natural := Get_Current_Layer; + A : Action renames L (Current_Layer, E.Row, E.Col); + begin + case E.Evt is + when Press => + case A.T is + when Key => + States (E.Col, E.Row) := + (Typ => Normal_Key, + Code => A.C, + Layer_Value => 0); + when Layer => + States (E.Col, E.Row) := (Typ => Layer_Mod, Layer_Value => A.L, Code => No); + when others => + raise Program_Error; + end case; + + when Release => + Release (E.Col, E.Row); + end case; + return False; + end Tick; + + Last_Was_Empty_Log : Boolean := False; + + procedure Tick (L : Layout) is + begin + for I in 1 .. Events_Ring_Buffers.Length(Queued_Events) loop + declare + E : Event := Events_Ring_Buffers.Last_Element (Queued_Events); + begin + Events_Ring_Buffers.Delete_Last (Queued_Events); + if Tick (L, E) then + Events_Ring_Buffers.Prepend (Queued_Events, E); + end if; + end; + end loop; + if not Last_Was_Empty_Log or else Events_Ring_Buffers.Length(Queued_Events) /= 0 then + Log ("End Tick layout, events: " & Events_Ring_Buffers.Length(Queued_Events)'Image); + Last_Was_Empty_Log := Events_Ring_Buffers.Length(Queued_Events) = 0; + end if; + end Tick; + + function Get_Key_Codes return Key_Codes_T is + Codes : Key_Codes_T (0 .. 10); + Wm: Natural := 0; + begin + for S of States loop + if S.Typ = Normal_Key and then + (S.Code < LCtrl or else S.Code > RGui) + then + Codes (Wm) := S.Code; + Wm := Wm + 1; + end if; + end loop; + + if Wm = 0 then + return []; + else + return Codes (0 .. Wm - 1); + end if; + end Get_Key_Codes; + + function Get_Modifiers return Key_Modifiers is + use USB.Device.HID.Keyboard; + KM : Key_Modifiers (1..8); + I : Natural := 0; + begin + for S of States loop + if S.Typ = Normal_Key then + I := I + 1; + case S.Code is + when LCtrl => + KM(I) := Ctrl_Left; + when RCtrl => + KM(I) := Ctrl_Right; + when LShift => + KM(I) := Shift_Left; + when RShift => + KM(I) := Shift_Right; + when LAlt => + KM(I) := Alt_Left; + when RAlt => + KM(I) := Alt_Right; + when LGui => + KM(I) := Meta_Left; + when RGui => + KM(I) := Meta_Right; + when others => + I := I - 1; + end case; + end if; + end loop; + return KM (1..I); + end Get_Modifiers; + + procedure Init is + begin + Events_Ring_Buffers.Clear (Queued_Events); + end Init; + +end Click; diff --git a/tests/syntax-tests/source/Ada/click.ads b/tests/syntax-tests/source/Ada/click.ads new file mode 100644 index 00000000..571f3601 --- /dev/null +++ b/tests/syntax-tests/source/Ada/click.ads @@ -0,0 +1,339 @@ +with HAL.GPIO; +with USB.Device.HID.Keyboard; + +generic + Nb_Bounce : Natural; + type ColR is (<>); + type RowR is (<>); + + type GPIOP is new HAL.GPIO.GPIO_Point with private; + + type Cols_T is array (ColR) of GPIOP; + type Rows_T is array (RowR) of GPIOP; + + Cols : Cols_T; + Rows : Rows_T; + Num_Layers : Natural; + + with procedure Log (S : String; L : Integer := 1; Deindent : Integer := 0); +package Click is + + type Keys_T is record + Cols : Cols_T; + Rows : Rows_T; + end record; + + Keys : Keys_T := + (Rows => Rows, Cols => Cols); + + type Key_Matrix is array (ColR, RowR) of Boolean; + + -------------------------- + -- Events & Debouncing -- + -------------------------- + + MaxEvents : constant Positive := 20; + + type EventT is (Press, Release); + type Event is record + Evt : EventT; + Col : ColR; + Row : RowR; + end record; + + type Events is array (Natural range <>) of Event; + + function Get_Events return Events; + function Update (NewS : Key_Matrix) return Boolean; + + ------------- + -- Layout -- + ------------- + --------------- + -- Keycodes -- + --------------- + + -- Keycodes copy/pasted from the excelent Keyberon Rust firmware: + -- https://github.com/TeXitoi/keyberon/ + + type Key_Code_T is + ( + -- The "no" key, a placeholder to express nothing. + No, -- = 0x00, + -- / Error if too much keys are pressed at + -- the same time. + ErrorRollOver, + -- / The POST fail error. + PostFail, + -- / An undefined error occured. + ErrorUndefined, + -- / `a` and `A`. + A, + B, + C, + D, + E, + F, + G, + H, + I, + J, + K, + L, + M, -- 0x10 + N, + O, + P, + Q, + R, + S, + T, + U, + V, + W, + X, + Y, + Z, + -- `1` and `!`. + Kb1, + -- `2` and `@`. + Kb2, + -- `3` and `#`. + Kb3, -- 0x20 + -- / `4` and `$`. + Kb4, + -- `5` and `%`. + Kb5, + -- `6` and `^`. + Kb6, + -- `7` and `&`. + Kb7, + -- `8` and `*`. + Kb8, + -- `9` and `(`. + Kb9, + -- `0` and `)`. + Kb0, + Enter, + Escape, + BSpace, + Tab, + Space, + -- `-` and `_`. + Minus, + -- `=` and `+`. + Equal, + -- `[` and `{`. + LBracket, + -- `]` and `}`. + RBracket, -- 0x30 + -- / `\` and `|`. + Bslash, + -- Non-US `#` and `~` (Typically near the Enter key). + NonUsHash, + -- `;` and `:`. + SColon, + -- `'` and `"`. + Quote, + -- How to have ` as code? + -- \` and `~`. + Grave, + -- `,` and `<`. + Comma, + -- `.` and `>`. + Dot, + -- `/` and `?`. + Slash, + CapsLock, + F1, + F2, + F3, + F4, + F5, + F6, + F7, -- 0x40 + F8, + F9, + F10, + F11, + F12, + PScreen, + ScrollLock, + Pause, + Insert, + Home, + PgUp, + Delete, + Endd, + PgDown, + Right, + Left, -- 0x50 + Down, + Up, + NumLock, + -- Keypad `/` + KpSlash, + -- Keypad `*` + KpAsterisk, + -- Keypad `-`. + KpMinus, + -- Keypad `+`. + KpPlus, + -- Keypad enter. + KpEnter, + -- Keypad 1. + Kp1, + Kp2, + Kp3, + Kp4, + Kp5, + Kp6, + Kp7, + Kp8, -- 0x60 + Kp9, + Kp0, + KpDot, + -- Non-US `\` and `|` (Typically near the Left-Shift key) + NonUsBslash, + Application, -- 0x65 + -- / not a key, used for errors + Power, + -- Keypad `=`. + KpEqual, + F13, + F14, + F15, + F16, + F17, + F18, + F19, + F20, + F21, -- 0x70 + F22, + F23, + F24, + Execute, + Help, + Menu, + Selectt, + Stop, + Again, + Undo, + Cut, + Copy, + Paste, + Find, + Mute, + VolUp, -- 0x80 + VolDown, + -- Deprecated. + LockingCapsLock, + -- Deprecated. + LockingNumLock, + -- Deprecated. + LockingScrollLock, + -- / Keypad `,`, also used for the + -- brazilian keypad period (.) key. + KpComma, + -- Used on AS/400 keyboard + KpEqualSign, + Intl1, + Intl2, + Intl3, + Intl4, + Intl5, + Intl6, + Intl7, + Intl8, + Intl9, + Lang1, -- 0x90 + Lang2, + Lang3, + Lang4, + Lang5, + Lang6, + Lang7, + Lang8, + Lang9, + AltErase, + SysReq, + Cancel, + Clear, + Prior, + Returnn, + Separator, + Outt, -- 0xA0 + Oper, + ClearAgain, + CrSel, + ExSel, + + -- According to QMK, 0xA5-0xDF are not + -- usable on modern keyboards + + -- Modifiers + -- Left Control. + LCtrl, -- = 0xE0, + -- / Left Shift. + LShift, + -- Left Alt. + LAlt, + -- Left GUI (the Windows key). + LGui, + -- Right Control. + RCtrl, + -- Right Shift. + RShift, + -- Right Alt (or Alt Gr).  + RAlt, + -- Right GUI (the Windows key). + RGui, -- 0xE7 + + -- Unofficial + MediaPlayPause, -- 0xE8, + MediaStopCD, + MediaPreviousSong, + MediaNextSong, + MediaEjectCD, + MediaVolUp, + MediaVolDown, + MediaMute, + MediaWWW, -- 0xF0 + MediaBack, + MediaForward, + MediaStop, + MediaFind, + MediaScrollUp, + MediaScrollDown, + MediaEdit, + MediaSleep, + MediaCoffee, + MediaRefresh, + MediaCalc -- 0xFB + ); + + type Action_Type is (Key, No_Op, Trans, Layer, Multiple_Actions); + + -- Should be a discriminated type + type Action is record + T : Action_Type; -- hould be the discriminant + C : Key_Code_T; + L : Natural; + end record; + + function Kw (Code : Key_Code_T) return Action; + function Lw (V : Natural) return Action; + + type Key_Modifiers is array (Natural range <>) of USB.Device.HID.Keyboard.Modifiers; + + type Key_Codes_T is array (Natural range <>) of Key_Code_T; + + subtype Ac is Action; + type Layout is array (0 .. Num_Layers - 1, RowR, ColR) of Action; + procedure Register_Events (L : Layout; Es : Events); + procedure Tick (L : Layout); + + function Get_Key_Codes return Key_Codes_T; + function Get_Modifiers return Key_Modifiers; + procedure Init; +end Click; diff --git a/tests/syntax-tests/source/Ada/click.gpr b/tests/syntax-tests/source/Ada/click.gpr new file mode 100644 index 00000000..27f9d5aa --- /dev/null +++ b/tests/syntax-tests/source/Ada/click.gpr @@ -0,0 +1,29 @@ +with "config/click_config.gpr"; +project Click is + + for Library_Name use "Click"; + for Library_Version use Project'Library_Name & ".so." & Click_Config.Crate_Version; + + for Source_Dirs use ("src/", "config/"); + for Object_Dir use "obj/" & Click_Config.Build_Profile; + for Create_Missing_Dirs use "True"; + for Library_Dir use "lib"; + + type Library_Type_Type is ("relocatable", "static", "static-pic"); + Library_Type : Library_Type_Type := + external ("CLICK_LIBRARY_TYPE", external ("LIBRARY_TYPE", "static")); + for Library_Kind use Library_Type; + + package Compiler is + for Default_Switches ("Ada") use Click_Config.Ada_Compiler_Switches & ("-gnatX", "-gnat2022"); + end Compiler; + + package Binder is + for Switches ("Ada") use ("-Es"); -- Symbolic traceback + end Binder; + + package Install is + for Artifacts (".") use ("share"); + end Install; + +end Click; From 0cc4e98560077a937c288e37988f676644e6e147 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Oct 2022 19:42:28 +0000 Subject: [PATCH 04/14] Bump actions/checkout from 2 to 3 Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/CICD.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 2ccb2f32..268e65c0 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -24,14 +24,14 @@ jobs: default: true profile: minimal components: rustfmt - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - run: cargo fmt -- --check license_checks: name: License checks runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: true # we especially want to perform license checks on submodules - run: tests/scripts/license-checks.sh @@ -43,7 +43,7 @@ jobs: MSRV_FEATURES: --no-default-features --features minimal-application,bugreport,build-assets steps: - name: Checkout source code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Install rust toolchain (v${{ env.MIN_SUPPORTED_RUST_VERSION }}) uses: actions-rs/toolchain@v1 @@ -68,7 +68,7 @@ jobs: runs-on: ubuntu-20.04 steps: - name: Git checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: submodules: true # we need all syntax and theme submodules - name: Install Rust toolchain @@ -113,7 +113,7 @@ jobs: runs-on: ubuntu-20.04 steps: - name: Git checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Prepare environment variables run: | echo "BAT_SYSTEM_CONFIG_PREFIX=$GITHUB_WORKSPACE/tests/examples/system_config" >> $GITHUB_ENV @@ -139,7 +139,7 @@ jobs: runs-on: ubuntu-20.04 steps: - name: Git checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Install Rust toolchain uses: actions-rs/toolchain@v1 with: @@ -186,7 +186,7 @@ jobs: - { target: x86_64-unknown-linux-musl , os: ubuntu-20.04, use-cross: true } steps: - name: Checkout source code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Install prerequisites shell: bash From 5fce1389e55ea1c4050393f850747194e3909785 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Oct 2022 19:43:21 +0000 Subject: [PATCH 05/14] Bump serde from 1.0.144 to 1.0.145 Bumps [serde](https://github.com/serde-rs/serde) from 1.0.144 to 1.0.145. - [Release notes](https://github.com/serde-rs/serde/releases) - [Commits](https://github.com/serde-rs/serde/compare/v1.0.144...v1.0.145) --- updated-dependencies: - dependency-name: serde dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4b063d4c..c85f77b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -970,18 +970,18 @@ checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" [[package]] name = "serde" -version = "1.0.144" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" +checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.144" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00" +checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" dependencies = [ "proc-macro2", "quote", From 375b392478586690f53b2667d356aba928ce8c57 Mon Sep 17 00:00:00 2001 From: John Higgins Date: Sun, 9 Oct 2022 22:41:27 -0700 Subject: [PATCH 06/14] Fixed reversed logic error for --chop-long-lines --- src/bin/bat/app.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index b52aa265..eeaa7b39 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -174,9 +174,8 @@ impl App { } _ => unreachable!("other values for --wrap are not allowed"), } - } - else { - WrappingMode::NoWrapping(true) + } else { + WrappingMode::Character } } else { // We don't have the tty width when piping to another program. From 236a2c57944d710332d97881188bafa720600269 Mon Sep 17 00:00:00 2001 From: John Higgins Date: Thu, 13 Oct 2022 23:52:15 -0700 Subject: [PATCH 07/14] Fixed inverted logic on -S and --chop-long-lines --- CHANGELOG.md | 1 + src/bin/bat/app.rs | 2 +- src/bin/bat/clap_app.rs | 2 +- tests/integration_tests.rs | 51 +++++++++++--------------------------- 4 files changed, 18 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 986e8a09..67332437 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # unreleased ## Features +- Implemented `-S` and `--chop-long-lines` flags as aliases for `--wrap=character`. See #2309 (@johnmatthiggins) ## Bugfixes diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index eeaa7b39..75e5a063 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -175,7 +175,7 @@ impl App { _ => unreachable!("other values for --wrap are not allowed"), } } else { - WrappingMode::Character + WrappingMode::NoWrapping(true) } } else { // We don't have the tty width when piping to another program. diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index 426f6171..c956bf5d 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -206,7 +206,7 @@ pub fn build_app(interactive_output: bool) -> Command<'static> { .long("chop-long-lines") .short('S') .takes_value(false) - .help("Truncate all lines longer than screen width. Alias for '--wrap=never'."), + .help("Truncate all lines longer than screen width. Alias for '--wrap=character'."), ) .arg( Arg::new("terminal-width") diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 3130f434..6417327f 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -1501,17 +1501,12 @@ fn ignored_suffix_arg() { #[test] fn no_line_wrapping_when_set_to_never() { - let expected = -"───────┬──────────────────────────────────────────────────────────────────────── - │ File: 80-columns.txt - │ Size: 101 B -───────┼──────────────────────────────────────────────────────────────────────── - 1 │ abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyz -───────┴──────────────────────────────────────────────────────────────────────── + let expected = "abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyz "; bat() - .arg("--style=full") + .arg("--style=rule") + .arg("--color=never") .arg("--decorations=always") .arg("--wrap=never") .arg("--terminal-width=80") @@ -1525,17 +1520,13 @@ fn no_line_wrapping_when_set_to_never() { #[test] fn line_wrapping_when_auto() { let expected = - "───────┬──────────────────────────────────────────────────────────────────────── - │ File: 80-columns.txt - │ Size: 101 B -───────┼──────────────────────────────────────────────────────────────────────── - 1 │ abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstu - │ vxyzabcdefghigklmnopqrstuvxyz -───────┴──────────────────────────────────────────────────────────────────────── + "abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcde +fghigklmnopqrstuvxyz "; bat() - .arg("--style=full") + .arg("--color=never") + .arg("--style=rule") .arg("--decorations=always") .arg("--wrap=auto") .arg("--terminal-width=80") @@ -1547,19 +1538,13 @@ fn line_wrapping_when_auto() { } #[test] -fn line_wrapping_with_s_flag() { +fn no_line_wrapping_with_s_flag() { let expected = - "───────┬──────────────────────────────────────────────────────────────────────── - │ File: 80-columns.txt - │ Size: 101 B -───────┼──────────────────────────────────────────────────────────────────────── - 1 │ abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstu - │ vxyzabcdefghigklmnopqrstuvxyz -───────┴──────────────────────────────────────────────────────────────────────── -"; + "abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyz\n"; bat() - .arg("--style=full") + .arg("--color=never") + .arg("--style=rule") .arg("--decorations=always") .arg("-S") .arg("--terminal-width=80") @@ -1571,19 +1556,13 @@ fn line_wrapping_with_s_flag() { } #[test] -fn chop_long_lines_when_specified() { +fn no_wrapping_with_chop_long_lines() { let expected = - "───────┬──────────────────────────────────────────────────────────────────────── - │ File: 80-columns.txt - │ Size: 101 B -───────┼──────────────────────────────────────────────────────────────────────── - 1 │ abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstu - │ vxyzabcdefghigklmnopqrstuvxyz -───────┴──────────────────────────────────────────────────────────────────────── -"; + "abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyz\n"; bat() - .arg("--style=full") + .arg("--color=never") + .arg("--style=rule") .arg("--decorations=always") .arg("--chop-long-lines") .arg("--terminal-width=80") From 20f272168ac155c2a4b78d6935d675f7d33603f3 Mon Sep 17 00:00:00 2001 From: John Higgins Date: Fri, 14 Oct 2022 14:23:51 -0700 Subject: [PATCH 08/14] Fixed typo in CHANGELOG.md for PR #2309 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67332437..e7869cc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # unreleased ## Features -- Implemented `-S` and `--chop-long-lines` flags as aliases for `--wrap=character`. See #2309 (@johnmatthiggins) +- Implemented `-S` and `--chop-long-lines` flags as aliases for `--wrap=never`. See #2309 (@johnmatthiggins) ## Bugfixes From 21bdcbb71f5bad9b1a458ea747cf0e9beda306a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Wed, 5 Oct 2022 20:31:20 +0300 Subject: [PATCH 09/14] Fix up punctuation and sorting in manual modifications doc --- doc/assets.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/assets.md b/doc/assets.md index 717d0919..56140e2f 100644 --- a/doc/assets.md +++ b/doc/assets.md @@ -77,12 +77,12 @@ themes (`bat cache --clear`). The following files have been manually modified after converting from a `.tmLanguage` file: -* `Apache.sublime_syntax`=> removed `.conf` and `.CONF` file types. +* `Apache.sublime_syntax`=> removed `conf` and `CONF` file types. * `Dart.sublime-syntax` => removed `#regex.dart` include. -* `INI.sublime-syntax` => added `.hgrc`, `hgrc`, and `desktop` file types and support for comments after section headers +* `INI.sublime-syntax` => added `.hgrc`, `hgrc`, and `desktop` file types and support for comments after section headers. * `Org mode.sublime-syntax` => removed `task` file type. +* `Robot.sublime_syntax` => changed name to "Robot Framework", added `.resource` extension. * `SML.sublime_syntax` => removed `ml` file type. -* `Robot.sublime_syntax` => changed name to "Robot Framework", added `.resource` extension ### Non-submodule additions From 9679ae36624b28c29803cc7b567acaf4924503ad Mon Sep 17 00:00:00 2001 From: wenzdey <56051809+wenzdey@users.noreply.github.com> Date: Fri, 7 Oct 2022 22:53:03 -0500 Subject: [PATCH 10/14] Updated Homebrew link macos and linux homebrew page now merged --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b1e24339..56534e37 100644 --- a/README.md +++ b/README.md @@ -367,7 +367,7 @@ Existing packages may be available, but are not officially supported and may con ### On macOS (or Linux) via Homebrew -You can install `bat` with [Homebrew on MacOS](https://formulae.brew.sh/formula/bat) or [Homebrew on Linux](https://formulae.brew.sh/formula-linux/bat): +You can install `bat` with [Homebrew](https://formulae.brew.sh/formula/bat): ```bash brew install bat From f215d07366dac50aa7068e9c3f8d5f46b09b4c1a Mon Sep 17 00:00:00 2001 From: wzy <32936898+Freed-Wu@users.noreply.github.com> Date: Tue, 18 Oct 2022 01:56:17 +0800 Subject: [PATCH 11/14] Improve Manpage.sublime-syntax, Fix #2353 (#2364) * Improve Manpage.sublime-syntax, Fix #2353 * Add highlight tests for fzf-0.33.0 --- CHANGELOG.md | 1 + .../syntaxes/02_Extra/Manpage.sublime-syntax | 6 +- .../highlighted/Manpage/fzf-0.33.0.man | 773 ++++++++++++++++++ .../source/Manpage/fzf-0.33.0.man | 773 ++++++++++++++++++ 4 files changed, 1550 insertions(+), 3 deletions(-) create mode 100644 tests/syntax-tests/highlighted/Manpage/fzf-0.33.0.man create mode 100644 tests/syntax-tests/source/Manpage/fzf-0.33.0.man diff --git a/CHANGELOG.md b/CHANGELOG.md index 986e8a09..c67fb827 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ ## Bugfixes - Bring back pre-processing of ANSI escape characters to so that some common `bat` use cases starts working again. See #2308 (@Enselic) +- Improve Manpage.sublime-syntax. See #2364 (@Freed-Wu) # v0.22.0 diff --git a/assets/syntaxes/02_Extra/Manpage.sublime-syntax b/assets/syntaxes/02_Extra/Manpage.sublime-syntax index b50dc19d..00a9bc73 100644 --- a/assets/syntaxes/02_Extra/Manpage.sublime-syntax +++ b/assets/syntaxes/02_Extra/Manpage.sublime-syntax @@ -75,7 +75,7 @@ contexts: options: # command-line options like --option=value, --some-flag, or -x - - match: '^[ ]{7}(?=-)' + - match: '^[ ]{7}(?=-|\+)' push: expect-command-line-option - match: '(?:[^a-zA-Z0-9_-]|^|\s){{command_line_option}}' captures: @@ -96,7 +96,7 @@ contexts: - include: env-var expect-command-line-option: - - match: '[A-Za-z0-9-]+' + - match: '[A-Za-z0-9-\.\?:#\$\+]+' scope: entity.name.command-line-option.man - match: '(\[)(=)' captures: @@ -122,7 +122,7 @@ contexts: pop: true expect-parameter: - - match: '[A-Za-z0-9-]+' + - match: '[A-Za-z0-9-_]+' scope: variable.parameter.man - match: (?=\s+\|) pop: true diff --git a/tests/syntax-tests/highlighted/Manpage/fzf-0.33.0.man b/tests/syntax-tests/highlighted/Manpage/fzf-0.33.0.man new file mode 100644 index 00000000..cf259ec9 --- /dev/null +++ b/tests/syntax-tests/highlighted/Manpage/fzf-0.33.0.man @@ -0,0 +1,773 @@ +fzf(1) fzf - a command-line fuzzy finder fzf(1) + +NAME + fzf - a command-line fuzzy finder + +SYNOPSIS + fzf [options] + +DESCRIPTION + fzf is a general-purpose command-line fuzzy finder. + +OPTIONS + Search mode + -x, --extended + Extended-search mode. Since 0.10.9, this is enabled by default. You can disable it with +x or --no-extended. + + -e, --exact + Enable exact-match + + -i Case-insensitive match (default: smart-case match) + + +i Case-sensitive match + + --literal + Do not normalize latin script letters for matching. + + --scheme=SCHEME + Choose scoring scheme tailored for different types of input. + + default Generic scoring scheme designed to work well with any type of input + path Scoring scheme for paths (additional bonus point only after path separator) + history Scoring scheme for command history (no additional bonus points). + Sets --tiebreak=index as well. + + --algo=TYPE + Fuzzy matching algorithm (default: v2) + + v2 Optimal scoring algorithm (quality) + v1 Faster but not guaranteed to find the optimal result (performance) + + -n, --nth=N[,..] + Comma-separated list of field index expressions for limiting search scope. See FIELD INDEX EXPRESSION for the details. + + --with-nth=N[,..] + Transform the presentation of each line using field index expressions + + -d, --delimiter=STR + Field delimiter regex for --nth and --with-nth (default: AWK-style) + + --disabled + Do not perform search. With this option, fzf becomes a simple selector interface rather than a "fuzzy finder". You can later enable the search using enable-search or toggle- + search action. + + Search result + +s, --no-sort + Do not sort the result + + --tac Reverse the order of the input + + e.g. + history | fzf --tac --no-sort + + --tiebreak=CRI[,..] + Comma-separated list of sort criteria to apply when the scores are tied. + + length Prefers line with shorter length + chunk Prefers line with shorter matched chunk (delimited by whitespaces) + begin Prefers line with matched substring closer to the beginning + end Prefers line with matched substring closer to the end + index Prefers line that appeared earlier in the input stream + + - Each criterion should appear only once in the list + - index is only allowed at the end of the list + - index is implicitly appended to the list when not specified + - Default is length (or equivalently length,index) + - If end is found in the list, fzf will scan each line backwards + + Interface + -m, --multi + Enable multi-select with tab/shift-tab. It optionally takes an integer argument which denotes the maximum number of items that can be selected. + + +m, --no-multi + Disable multi-select + + --no-mouse + Disable mouse + + --bind=KEYBINDS + Comma-separated list of custom key bindings. See KEY/EVENT BINDINGS for the details. + + --cycle + Enable cyclic scroll + + --keep-right + Keep the right end of the line visible when it's too long. Effective only when the query string is empty. + + --scroll-off=LINES + Number of screen lines to keep above or below when scrolling to the top or to the bottom (default: 0). + + --no-hscroll + Disable horizontal scroll + + --hscroll-off=COLS + Number of screen columns to keep to the right of the highlighted substring (default: 10). Setting it to a large value will cause the text to be positioned on the center of the + screen. + + --filepath-word + Make word-wise movements and actions respect path separators. The following actions are affected: + + backward-kill-word + backward-word + forward-word + kill-word + + --jump-labels=CHARS + Label characters for jump and jump-accept + + Layout + --height=HEIGHT[%] + Display fzf window below the cursor with the given height instead of using the full screen. + + --min-height=HEIGHT + Minimum height when --height is given in percent (default: 10). Ignored when --height is not specified. + + --layout=LAYOUT + Choose the layout (default: default) + + default Display from the bottom of the screen + reverse Display from the top of the screen + reverse-list Display from the top of the screen, prompt at the bottom + + --reverse + A synonym for --layout=reverse + + --border[=BORDER_OPT] + Draw border around the finder + + rounded Border with rounded corners (default) + sharp Border with sharp corners + horizontal Horizontal lines above and below the finder + vertical Vertical lines on each side of the finder + top (up) + bottom (down) + left + right + none + + --no-unicode + Use ASCII characters instead of Unicode box drawing characters to draw border + + --margin=MARGIN + Comma-separated expression for margins around the finder. + + TRBL Same margin for top, right, bottom, and left + TB,RL Vertical, horizontal margin + T,RL,B Top, horizontal, bottom margin + T,R,B,L Top, right, bottom, left margin + + Each part can be given in absolute number or in percentage relative to the terminal size with % suffix. + + e.g. + fzf --margin 10% + fzf --margin 1,5% + + --padding=PADDING + Comma-separated expression for padding inside the border. Padding is distinguishable from margin only when --border option is used. + + e.g. + fzf --margin 5% --padding 5% --border --preview 'cat {}' \ + --color bg:#222222,preview-bg:#333333 + + TRBL Same padding for top, right, bottom, and left + TB,RL Vertical, horizontal padding + T,RL,B Top, horizontal, bottom padding + T,R,B,L Top, right, bottom, left padding + + --info=STYLE + Determines the display style of finder info. + + default Display on the next line to the prompt + inline Display on the same line + hidden Do not display finder info + + --no-info + A synonym for --info=hidden + + --prompt=STR + Input prompt (default: '> ') + + --pointer=STR + Pointer to the current line (default: '>') + + --marker=STR + Multi-select marker (default: '>') + + --header=STR + The given string will be printed as the sticky header. The lines are displayed in the given order from top to bottom regardless of --layout option, and are not affected by + --with-nth. ANSI color codes are processed even when --ansi is not set. + + --header-lines=N + The first N lines of the input are treated as the sticky header. When --with-nth is set, the lines are transformed just like the other lines that follow. + + --header-first + Print header before the prompt line + + --ellipsis=STR + Ellipsis to show when line is truncated (default: '..') + + Display + --ansi Enable processing of ANSI color codes + + --tabstop=SPACES + Number of spaces for a tab character (default: 8) + + --color=[BASE_SCHEME][,COLOR_NAME[:ANSI_COLOR][:ANSI_ATTRIBUTES]]... + Color configuration. The name of the base color scheme is followed by custom color mappings. + + BASE SCHEME: + (default: dark on 256-color terminal, otherwise 16) + + dark Color scheme for dark 256-color terminal + light Color scheme for light 256-color terminal + 16 Color scheme for 16-color terminal + bw No colors (equivalent to --no-color) + + COLOR NAMES: + fg Text + bg Background + preview-fg Preview window text + preview-bg Preview window background + hl Highlighted substrings + fg+ Text (current line) + bg+ Background (current line) + gutter Gutter on the left (defaults to bg+) + hl+ Highlighted substrings (current line) + query Query string + disabled Query string when search is disabled + info Info line (match counters) + border Border around the window (--border and --preview) + prompt Prompt + pointer Pointer to the current line + marker Multi-select marker + spinner Streaming input indicator + header Header + + ANSI COLORS: + -1 Default terminal foreground/background color + (or the original color of the text) + 0 ~ 15 16 base colors + black + red + green + yellow + blue + magenta + cyan + white + bright-black (gray | grey) + bright-red + bright-green + bright-yellow + bright-blue + bright-magenta + bright-cyan + bright-white + 16 ~ 255 ANSI 256 colors + #rrggbb 24-bit colors + + ANSI ATTRIBUTES: (Only applies to foreground colors) + regular Clears previously set attributes; should precede the other ones + bold + underline + reverse + dim + italic + strikethrough + + EXAMPLES: + + # Seoul256 theme with 8-bit colors + # (https://github.com/junegunn/seoul256.vim) + fzf --color='bg:237,bg+:236,info:143,border:240,spinner:108' \ + --color='hl:65,fg:252,header:65,fg+:252' \ + --color='pointer:161,marker:168,prompt:110,hl+:108' + + # Seoul256 theme with 24-bit colors + fzf --color='bg:#4B4B4B,bg+:#3F3F3F,info:#BDBB72,border:#6B6B6B,spinner:#98BC99' \ + --color='hl:#719872,fg:#D9D9D9,header:#719872,fg+:#D9D9D9' \ + --color='pointer:#E12672,marker:#E17899,prompt:#98BEDE,hl+:#98BC99' + + --no-bold + Do not use bold text + + --black + Use black background + + History + --history=HISTORY_FILE + Load search history from the specified file and update the file on completion. When enabled, CTRL-N and CTRL-P are automatically remapped to next-history and previous-history. + + --history-size=N + Maximum number of entries in the history file (default: 1000). The file is automatically truncated when the number of the lines exceeds the value. + + Preview + --preview=COMMAND + Execute the given command for the current line and display the result on the preview window. {} in the command is the placeholder that is replaced to the single-quoted string of + the current line. To transform the replacement string, specify field index expressions between the braces (See FIELD INDEX EXPRESSION for the details). + + e.g. + fzf --preview='head -$LINES {}' + ls -l | fzf --preview="echo user={3} when={-4..-2}; cat {-1}" --header-lines=1 + + fzf exports $FZF_PREVIEW_LINES and $FZF_PREVIEW_COLUMNS so that they represent the exact size of the preview window. (It also overrides $LINES and $COLUMNS with the same values + but they can be reset by the default shell, so prefer to refer to the ones with FZF_PREVIEW_ prefix.) + + A placeholder expression starting with + flag will be replaced to the space-separated list of the selected lines (or the current line if no selection was made) individually + quoted. + + e.g. + fzf --multi --preview='head -10 {+}' + git log --oneline | fzf --multi --preview 'git show {+1}' + + When using a field index expression, leading and trailing whitespace is stripped from the replacement string. To preserve the whitespace, use the s flag. + + Also, {q} is replaced to the current query string, and {n} is replaced to zero-based ordinal index of the line. Use {+n} if you want all index numbers when multiple lines are + selected. + + A placeholder expression with f flag is replaced to the path of a temporary file that holds the evaluated list. This is useful when you multi-select a large number of items and + the length of the evaluated string may exceed ARG_MAX. + + e.g. + # Press CTRL-A to select 100K items and see the sum of all the numbers. + # This won't work properly without 'f' flag due to ARG_MAX limit. + seq 100000 | fzf --multi --bind ctrl-a:select-all \ + --preview "awk '{sum+=\$1} END {print sum}' {+f}" + + Note that you can escape a placeholder pattern by prepending a backslash. + + Preview window will be updated even when there is no match for the current query if any of the placeholder expressions evaluates to a non-empty string. + + Since 0.24.0, fzf can render partial preview content before the preview command completes. ANSI escape sequence for clearing the display (CSI 2 J) is supported, so you can use + it to implement preview window that is constantly updating. + + e.g. + fzf --preview 'for i in $(seq 100000); do + (( i % 200 == 0 )) && printf "\033[2J" + echo "$i" + sleep 0.01 + done' + + --preview-window=[POSITION][,SIZE[%]][,border-BORDER_OPT][,[no]wrap][,[no]follow][,[no]cycle][,[no]hidden][,+SCROLL[OFFSETS][/DENOM]][,~HEADER_LINES][,default][,