diff options
| author | tv <tv@krebsco.de> | 2026-03-09 03:35:50 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-03-09 03:35:50 +0100 |
| commit | a648d77052f04d4731d728fc317a0947b35a3ed5 (patch) | |
| tree | 2e125e5f3a0a5d29884dcb35e729523153e00a5c /src/TextViewport/Render/Segmentation.hs | |
| parent | bff24914f21800719c99c80165a8c3a3759311e7 (diff) | |
Diffstat (limited to 'src/TextViewport/Render/Segmentation.hs')
| -rw-r--r-- | src/TextViewport/Render/Segmentation.hs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/TextViewport/Render/Segmentation.hs b/src/TextViewport/Render/Segmentation.hs index 3d64748..2ec530a 100644 --- a/src/TextViewport/Render/Segmentation.hs +++ b/src/TextViewport/Render/Segmentation.hs @@ -13,11 +13,29 @@ import Data.Text qualified as T import Data.Vector (Vector) import Data.Vector qualified as V import Text.Hyphenation qualified as H -import TextViewport.Buffer.Item import TextViewport.Render.RenderedLine (RenderedLine(..)) -- TODO qualified -applyStrategy :: (Hashable t, Textual t, Index t ~ Int) => SegmentStrategy t -> Int -> Int -> t -> Vector (RenderedLine t) +-- | User-pluggable segmentation interface +class Segmenter seg a where + applySeg :: seg -> Int -> Int -> a -> Vector (RenderedLine a) + +-- | Built-in segmentation strategies (backwards compatible) +data BuiltinSeg a + = NoSegments + | FixedWidthSegments + | HyphenateSegments + { hsLang :: H.Language + , hsCache :: HM.HashMap a [(a, a)] + } + deriving (Eq, Show) + +-- | Built-in instance +instance (Hashable a, Textual a, Index a ~ Int) => Segmenter (BuiltinSeg a) a where + applySeg = applyStrategy + + +applyStrategy :: (Hashable a, Textual a, Index a ~ Int) => BuiltinSeg a -> Int -> Int -> a -> Vector (RenderedLine a) applyStrategy NoSegments width itemIx txt = let rawLines = S.splitWhen (=='\n') txt |
