termonad 4.3.0.0 → 4.4.0.0
raw patch · 10 files changed
+176/−23 lines, 10 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Termonad.Term: eventButtonToEvent :: EventButton -> Event
- Termonad.Config.Colour: lensBackgroundColour :: forall c_a1j6Z. Lens' (ColourConfig c_a1j6Z) (Option c_a1j6Z)
+ Termonad.Config.Colour: lensBackgroundColour :: forall c_a1jnB. Lens' (ColourConfig c_a1jnB) (Option c_a1jnB)
- Termonad.Config.Colour: lensCursorBgColour :: forall c_a1j6Z. Lens' (ColourConfig c_a1j6Z) (Option c_a1j6Z)
+ Termonad.Config.Colour: lensCursorBgColour :: forall c_a1jnB. Lens' (ColourConfig c_a1jnB) (Option c_a1jnB)
- Termonad.Config.Colour: lensCursorFgColour :: forall c_a1j6Z. Lens' (ColourConfig c_a1j6Z) (Option c_a1j6Z)
+ Termonad.Config.Colour: lensCursorFgColour :: forall c_a1jnB. Lens' (ColourConfig c_a1jnB) (Option c_a1jnB)
- Termonad.Config.Colour: lensForegroundColour :: forall c_a1j6Z. Lens' (ColourConfig c_a1j6Z) (Option c_a1j6Z)
+ Termonad.Config.Colour: lensForegroundColour :: forall c_a1jnB. Lens' (ColourConfig c_a1jnB) (Option c_a1jnB)
- Termonad.Config.Colour: lensHighlightBgColour :: forall c_a1j6Z. Lens' (ColourConfig c_a1j6Z) (Option c_a1j6Z)
+ Termonad.Config.Colour: lensHighlightBgColour :: forall c_a1jnB. Lens' (ColourConfig c_a1jnB) (Option c_a1jnB)
- Termonad.Config.Colour: lensHighlightFgColour :: forall c_a1j6Z. Lens' (ColourConfig c_a1j6Z) (Option c_a1j6Z)
+ Termonad.Config.Colour: lensHighlightFgColour :: forall c_a1jnB. Lens' (ColourConfig c_a1jnB) (Option c_a1jnB)
- Termonad.Config.Colour: lensPalette :: forall c_a1j6Z. Lens' (ColourConfig c_a1j6Z) (Palette c_a1j6Z)
+ Termonad.Config.Colour: lensPalette :: forall c_a1jnB. Lens' (ColourConfig c_a1jnB) (Palette c_a1jnB)
- Termonad.Term: handleMousePress :: Terminal -> EventButton -> IO Bool
+ Termonad.Term: handleMousePress :: ApplicationWindow -> Terminal -> EventButton -> IO Bool
Files
- .nix-helpers/nixpkgs.nix +26/−7
- .nix-helpers/overlays.nix +23/−0
- CHANGELOG.md +13/−4
- README.md +19/−0
- default.nix +1/−0
- shell.nix +5/−4
- src/Termonad/Term.hs +64/−6
- src/Termonad/Types.hs +5/−1
- termonad.cabal +1/−1
- test/readme/README.lhs +19/−0
.nix-helpers/nixpkgs.nix view
@@ -2,27 +2,42 @@ # imported with an overlay adding Termonad. It is imported from various other # files. -{ # String representing a GHC version to use. Normally something like- # "ghc865". If null, then use a known-working GHC version.- compiler ? null-, # A path to nixpkgs. This will be imported. If null, use a known-working+{ # A path to nixpkgs. This will be imported. If null, use a known-working # nixpkgs version. nixpkgs ? null , # Additional overlays to apply when importing nixpkgs. additionalOverlays ? []+, # String representing a GHC version to use. Normally something like+ # "ghc865". If null, then use a known-working GHC version.+ compiler ? null , # Build all the examples bundled with termonad. Normally this is only used # in CI for testing that the examples all still compile. buildExamples ? false+, # Enable SIXEL support in VTE.+ #+ # Setting this to true builds the VTE library with SIXEL enabled. Note that+ # this uses a special version of VTE that may still have issues. This is+ # necessary because VTE doesn't yet support SIXEL by default in their release+ # versions. See https://github.com/cdepillabout/termonad/pull/221 and+ # https://github.com/cdepillabout/termonad/pull/219 for more information and+ # examples of what SIXEL looks like in Termonad.+ #+ # Also, see https://gitlab.gnome.org/GNOME/vte/-/issues/253 which seems to be+ # the upstream VTE issue for the SIXEL implementation.+ #+ # TODO: Remove this option when the upstream VTE releases officially support+ # SIXEL.+ enableSixelSupport ? false , # This is only used for `termonadShell`. # # If this is `true`, Hoogle will also index the Termonad libraries, # however this will mean the environment will need to be rebuilt every # time the termonad source changes. indexTermonad ? false- # Extra Haskell packages that will be visible by Termonad when it compiles+, # Extra Haskell packages that will be visible by Termonad when it compiles # itself. See ./termonad-with-packages.nix for an example of how to use # this.-, extraHaskellPackages ? null+ extraHaskellPackages ? null }: let@@ -39,7 +54,9 @@ haskellPackagesOverlays = import ./overlays.nix; - # This overlays sets some of the options use we at development time.+ # This overlay sets some of the options use we at development time. This+ # overlay is basically an easy way to pass options to `./overlays.nix`+ # without having to do it explicitly. termonadOptionsOverlay = self: super: { termonadCompilerVersion = if isNull compiler then super.termonadCompilerVersion else compiler;@@ -50,6 +67,8 @@ termonadExtraHaskellPackages = if isNull extraHaskellPackages then super.termonadExtraHaskellPackages else extraHaskellPackages;++ termonadEnableSixelSupport = enableSixelSupport; }; in
.nix-helpers/overlays.nix view
@@ -34,6 +34,7 @@ ! any (flip hasPrefix (baseNameOf path)) [ "dist" ".ghc" ]; }; + extraCabal2nixOptions = self.lib.optionalString self.termonadBuildExamples "-fbuildexamples"; @@ -54,6 +55,25 @@ }; }; + vte =+ if self.termonadEnableSixelSupport then+ super.vte.overrideAttrs (oldAttrs: {+ # As of 2022-10-20, VTE from Nixpkgs doesn't have sixel enabled by default.+ # We enable it here.+ mesonFlags = oldAttrs.mesonFlags ++ [ "-Dsixel=true" ];+ # As of 2022-10-20, the released version of VTE doesn't even include SIXEL+ # support, because upstream says it still has bugs. See+ # https://github.com/cdepillabout/termonad/pull/221#discussion_r997222069+ # and https://gitlab.gnome.org/GNOME/vte/-/issues/253 for more information.+ src = self.fetchurl {+ # This is VTE master as of 2022-10-17.+ url = "https://github.com/GNOME/vte/archive/8ef3f6b2f8043d28cbc82520eb094f09333b26ae.tar.gz";+ sha256 = "sha256-2V3dTTu9EH7sO2NeWWZ7pOurQopV/Ji+muoS6+IMNrA=";+ };+ })+ else+ super.vte;+ # This defines which compiler version is used to build Termonad. # # Either this, or termonadKnownWorkingHaskellPkgSet can be changed in an overlay@@ -71,6 +91,9 @@ # See ./nixpkgs.nix for an explanation of what this does. termonadIndexTermonad = false;++ # See ./nixpkgs.nix for an explanation of what this does.+ termonadEnableSixelSupport = false; # This is a shell environment for hacking on Termonad with cabal. See the # top-level shell.nix for an explanation.
CHANGELOG.md view
@@ -1,10 +1,19 @@+## 4.4.0.0++* Add support for opening URLs in a browser by right-clicking on them.+ URLs will also become underlined if you mouse-over them.+ [#222](https://github.com/cdepillabout/termonad/pull/222)+ ## 4.3.0.0 * Add SIXEL support. Note that you will need to set `enableSixel` to `True`- in your `ConfigOptions`, as well as using a version of VTE that is >= 0.63- for this option to have any affect. There is also a report that even if you- enable SIXEL and have a supported version of VTE, SIXEL doesn't work. See- the linked PR for more information. Thanks [@junjihashimoto](https://github.com/junjihashimoto)!+ in your `ConfigOptions`. In order for `enableSixel` to have any affect,+ you'll need to use version of VTE that is >= 0.63, and has been compiled+ with SIXEL support. There is also a report that even if you enable SIXEL+ and have a supported version of VTE, there may still be some problems. See+ the linked PR for more information, including how to compile VTE with SIXEL+ support. Thanks+ [@junjihashimoto](https://github.com/junjihashimoto)! [#219](https://github.com/cdepillabout/termonad/pull/219) ## 4.2.0.1
README.md view
@@ -495,6 +495,25 @@ [`.nix-helpers/termonad-with-packages.nix`](./.nix-helpers/termonad-with-packages.nix) file. +## Additional Info++This section contains some additional info that may be helpful for using Termonad.++### Opening URLs by right-clicking++It is possible to open a URL in a browser by right-clicking on it, and+selecting `Open URL in browser`. In order for this you work, you may+have to setup your XDG defaults. You can set the default browser to+Firefox with a command like the following:++```console+$ xdg-mime default firefox.desktop x-scheme-handler/http+$ xdg-mime default firefox.desktop x-scheme-handler/https+```++This `xdg-mime` executable comes from a package called `xdg-utils` in both+Nixpkgs and Ubutun/Debian.+ ## Goals Termonad has the following goals:
default.nix view
@@ -21,6 +21,7 @@ , additionalOverlays ? [] , compiler ? null , buildExamples ? false+, enableSixelSupport ? false }@args: (import .nix-helpers/nixpkgs.nix args).termonad-with-packages
shell.nix view
@@ -24,11 +24,12 @@ # will also index the Termonad libraries, however this will mean the environment # will need to be rebuilt every time the termonad source changes. -{ compiler ? null-, indexTermonad ? false-, nixpkgs ? null-, buildExamples ? false+{ nixpkgs ? null , additionalOverlays ? []+, compiler ? null+, buildExamples ? false+, enableSixelSupport ? false+, indexTermonad ? false }@args: (import .nix-helpers/nixpkgs.nix args).termonadShell
src/Termonad/Term.hs view
@@ -8,7 +8,8 @@ import Data.Colour.SRGB (Colour, RGB(RGB), toSRGB) import Data.FocusList (appendFL, deleteFL, getFocusItemFL) import GI.Gdk- ( EventButton+ ( Event (Event)+ , EventButton , EventKey , RGBA , getEventButtonButton@@ -16,12 +17,16 @@ , setRGBABlue , setRGBAGreen , setRGBARed+ , pattern BUTTON_SECONDARY+ , pattern CURRENT_TIME )-import GI.Gdk.Constants (pattern BUTTON_SECONDARY) import GI.Gio ( Cancellable+ , actionMapAddAction , menuAppend , menuNew+ , onSimpleActionActivate+ , simpleActionNew ) import GI.GLib ( SpawnFlags(SpawnFlagsDefault)@@ -40,6 +45,7 @@ , ReliefStyle(ReliefStyleNone) , ResponseType(ResponseTypeNo, ResponseTypeYes) , ScrolledWindow+ , Window , applicationGetActiveWindow , boxNew , buttonNewFromIconName@@ -71,6 +77,7 @@ , scrolledWindowNew , scrolledWindowSetPolicy , setWidgetMargin+ , showUriOnWindow , widgetDestroy , widgetGrabFocus , widgetSetCanFocus@@ -86,7 +93,11 @@ , Terminal , onTerminalChildExited , onTerminalWindowTitleChanged+ , regexNewForMatch+ , terminalGetAllowHyperlink , terminalGetWindowTitle+ , terminalMatchAddRegex+ , terminalMatchCheckEvent , terminalNew , terminalSetBoldIsBright , terminalSetCursorBlinkMode@@ -133,6 +144,9 @@ , tmNotebookTabTermContainer , tmNotebookTabs )+import Data.Coerce (coerce)+import Data.GI.Base (toManagedPtr)+import Termonad.Pcre (pcre2Multiline) focusTerm :: Int -> TMState -> IO () focusTerm i mvarTMState = do@@ -473,9 +487,26 @@ relabelTab notebook tabLabel scrolledWin vteTerm void $ onWidgetKeyPressEvent vteTerm $ handleKeyPress mvarTMState void $ onWidgetKeyPressEvent scrolledWin $ handleKeyPress mvarTMState- void $ onWidgetButtonPressEvent vteTerm $ handleMousePress vteTerm+ void $ onWidgetButtonPressEvent vteTerm $ handleMousePress tmStateAppWin vteTerm void $ onTerminalChildExited vteTerm $ \_ -> termExit notebookTab mvarTMState + -- Underline URLs so that the user can see they are right-clickable.+ --+ -- This regex is from https://www.regextester.com/94502+ --+ -- TODO: Roxterm and gnome-terminal have a much more in-depth set of regexes+ -- for URLs and things similar to URLs. At some point it might make sense to+ -- switch to something like this:+ -- https://github.com/realh/roxterm/blob/30f1faf8be4ccac8ba12b59feb5b8f758bc65a7b/src/roxterm-regex.c+ -- and+ -- https://github.com/realh/roxterm/blob/30f1faf8be4ccac8ba12b59feb5b8f758bc65a7b/src/terminal-regex.h+ let regexPat =+ "(?:http(s)?:\\/\\/)[\\w.-]+(?:\\.[\\w\\.-]+)+[\\w\\-\\._~:/?#[\\]@!\\$&'\\(\\)\\*\\+,;=.]+"+ -- We must set the pcre2Multiline option, otherwise VTE prints a warning.+ let pcreFlags = fromIntegral pcre2Multiline+ regex <- regexNewForMatch regexPat (fromIntegral $ length regexPat) pcreFlags+ void $ terminalMatchAddRegex vteTerm regex 0+ -- Put the keyboard focus on the term setFocusOn tmStateAppWin vteTerm @@ -487,12 +518,31 @@ pure tmTerm -- | Popup the context menu on right click-handleMousePress :: Terminal -> EventButton -> IO Bool-handleMousePress vteTerm event = do- button <- getEventButtonButton event+handleMousePress :: ApplicationWindow -> Terminal -> EventButton -> IO Bool+handleMousePress win vteTerm eventButton = do+ x <- terminalGetAllowHyperlink vteTerm+ print x+ button <- getEventButtonButton eventButton let rightClick = button == fromIntegral BUTTON_SECONDARY when rightClick $ do menuModel <- menuNew++ -- if the user right-clicked on a URL, add an option to open the URL+ -- in a browser+ (maybeUrl, _regexId) <- terminalMatchCheckEvent vteTerm (eventButtonToEvent eventButton)+ case maybeUrl of+ Nothing -> pure ()+ Just url -> do+ openUrlAction <- simpleActionNew "openurl" Nothing+ void $ onSimpleActionActivate openUrlAction $ \_ ->+ showUriOnWindow (Nothing :: Maybe Window) url (fromIntegral CURRENT_TIME)+ -- This will add the openurl action to the Application Window's action+ -- map everytime the user right-clicks on a URL. It is okay to add+ -- actions multiple times.+ actionMapAddAction win openUrlAction+ menuAppend menuModel (Just "Open URL in browser") (Just "win.openurl")++ menuAppend menuModel (Just "Copy") (Just "app.copy") menuAppend menuModel (Just "Paste") (Just "app.paste") menuAppend menuModel (Just "Preferences") (Just "app.preferences")@@ -500,3 +550,11 @@ menuAttachToWidget menu vteTerm Nothing menuPopupAtPointer menu Nothing pure rightClick++-- The terminalMatchCheckEvent function takes an Event, while we only+-- have an EventButton. It is apparently okay to just cast an EventButton+-- to an Event, since they are just pointers under the hood, and they+-- are laid out the same in memory. See+-- https://github.com/haskell-gi/haskell-gi/issues/109+eventButtonToEvent :: EventButton -> Event+eventButtonToEvent = Event . coerce . toManagedPtr
src/Termonad/Types.hs view
@@ -411,7 +411,11 @@ , enableSixel :: !Bool -- ^ Enable SIXEL to draw graphics in a terminal. --- -- Note that SIXEL may not be fully supported in VTE. Follow+ -- In order for this option to do anything, you need to be using a version+ -- of VTE >= 0.63, and compile VTE with SIXEL support.+ --+ -- Note that even if you do the above, there may still be some problems+ -- with SIXEL support in VTE. Follow -- <https://gitlab.gnome.org/GNOME/vte/-/issues/253> for more information. } deriving (Eq, Generic, FromJSON, Show, ToJSON)
termonad.cabal view
@@ -1,5 +1,5 @@ name: termonad-version: 4.3.0.0+version: 4.4.0.0 synopsis: Terminal emulator configurable in Haskell description: Termonad is a terminal emulator configurable in Haskell. It is extremely
test/readme/README.lhs view
@@ -495,6 +495,25 @@ [`.nix-helpers/termonad-with-packages.nix`](./.nix-helpers/termonad-with-packages.nix) file. +## Additional Info++This section contains some additional info that may be helpful for using Termonad.++### Opening URLs by right-clicking++It is possible to open a URL in a browser by right-clicking on it, and+selecting `Open URL in browser`. In order for this you work, you may+have to setup your XDG defaults. You can set the default browser to+Firefox with a command like the following:++```console+$ xdg-mime default firefox.desktop x-scheme-handler/http+$ xdg-mime default firefox.desktop x-scheme-handler/https+```++This `xdg-mime` executable comes from a package called `xdg-utils` in both+Nixpkgs and Ubutun/Debian.+ ## Goals Termonad has the following goals: