diff options
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 |
