summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authortv <tv@shackspace.de>2014-12-28 03:36:43 +0100
committertv <tv@shackspace.de>2015-10-17 01:49:52 +0200
commit3c0ed789dfa6b67a7853da0f2ea744a70c528d3a (patch)
tree86df7a25cc06b193ec086658f036fc451e5941f1 /src
parent21743b1d3353baf2557a818bcf70b7893549ec8b (diff)
store Trammel String in buffers
Diffstat (limited to 'src')
-rw-r--r--src/Trammel.hs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/Trammel.hs b/src/Trammel.hs
index 36c1140..bd3cd32 100644
--- a/src/Trammel.hs
+++ b/src/Trammel.hs
@@ -4,6 +4,7 @@
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
+{-# LANGUAGE LambdaCase #-}
module Trammel where
import Control.Applicative
@@ -214,3 +215,33 @@ pp t = renderString emptyRenderState t ""
renderSGR :: Pm -> String
renderSGR [] = []
renderSGR xs = ("\ESC["++) . (++"m") . intercalate ";" $ map show xs
+
+
+trammelDrop :: Int -> Trammel String -> Trammel String
+trammelDrop n = \case
+ Append t1 t2 ->
+ case compare n (len t1) of
+ LT -> Append (trammelDrop n t1) t2
+ EQ -> t2
+ GT -> trammelDrop (n - len t1) t2
+ Plain s ->
+ Plain (drop n s)
+ SGR pm t ->
+ SGR pm (trammelDrop n t)
+ Empty ->
+ Empty
+
+
+trammelTake :: Int -> Trammel String -> Trammel String
+trammelTake n = \case
+ Append t1 t2 ->
+ case compare n (len t1) of
+ LT -> trammelTake n t1
+ EQ -> t1
+ GT -> Append t1 (trammelTake (n - len t1) t2)
+ Plain s ->
+ Plain (take n s)
+ SGR pm t ->
+ SGR pm (trammelTake n t)
+ Empty ->
+ Empty