Compare commits
No commits in common. "master" and "1.0.0.0" have entirely different histories.
6 changed files with 9 additions and 46 deletions
|
|
@ -1,9 +1,5 @@
|
||||||
# Changelog for profold
|
# Changelog for profold
|
||||||
|
|
||||||
## Upcoming
|
|
||||||
* clean up code
|
|
||||||
* document functions
|
|
||||||
|
|
||||||
## 1.0.0.0
|
## 1.0.0.0
|
||||||
* add readme
|
* add readme
|
||||||
* create project
|
* create project
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
import Brick
|
import Brick
|
||||||
|
|
@ -9,6 +11,9 @@ import Profold.App
|
||||||
import Profold.Options
|
import Profold.Options
|
||||||
import Profold.ParseProfFile
|
import Profold.ParseProfFile
|
||||||
|
|
||||||
|
data UiName = UiViewport
|
||||||
|
deriving (Show, Eq, Ord)
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
opts <- execParser options
|
opts <- execParser options
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,7 @@
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
-- | This module implements a brick application for browsing a 'LineNode' tree.
|
|
||||||
|
|
||||||
module Profold.App
|
module Profold.App
|
||||||
( UiState
|
( UiState
|
||||||
, UiName
|
|
||||||
, newUiState
|
, newUiState
|
||||||
, myApp
|
, myApp
|
||||||
) where
|
) where
|
||||||
|
|
@ -17,24 +14,16 @@ import qualified Graphics.Vty as Vty
|
||||||
|
|
||||||
import Profold.LineNode
|
import Profold.LineNode
|
||||||
|
|
||||||
-- | Unique names for UI elements used in this application.
|
|
||||||
data UiName = UiList
|
data UiName = UiList
|
||||||
deriving (Show, Eq, Ord)
|
deriving (Show, Eq, Ord)
|
||||||
|
|
||||||
-- | The state for the brick application.
|
|
||||||
data UiState = UiState
|
data UiState = UiState
|
||||||
{ uiInfo :: [T.Text]
|
{ uiInfo :: [T.Text]
|
||||||
, uiTree :: LineNode
|
, uiTree :: LineNode
|
||||||
, uiList :: List UiName (Path, LineNode)
|
, uiList :: List UiName (Path, LineNode)
|
||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
-- | Create an initial ui state.
|
newUiState :: [T.Text] -> LineNode -> UiState
|
||||||
newUiState
|
|
||||||
:: [T.Text]
|
|
||||||
-- ^ A list of lines which should contain the column labels. These lines will always be displayed at the top of the screen.
|
|
||||||
-> LineNode
|
|
||||||
-- ^ The tree to display.
|
|
||||||
-> UiState
|
|
||||||
newUiState info ln = toggleFold $ UiState info ln $ list UiList (flatten ln) 1
|
newUiState info ln = toggleFold $ UiState info ln $ list UiList (flatten ln) 1
|
||||||
|
|
||||||
toggleFold :: UiState -> UiState
|
toggleFold :: UiState -> UiState
|
||||||
|
|
@ -85,7 +74,6 @@ myAttrMap = attrMap Vty.defAttr
|
||||||
, ("info", Vty.defAttr `Vty.withStyle` Vty.reverseVideo)
|
, ("info", Vty.defAttr `Vty.withStyle` Vty.reverseVideo)
|
||||||
]
|
]
|
||||||
|
|
||||||
-- | The brick application.
|
|
||||||
myApp :: App UiState () UiName
|
myApp :: App UiState () UiName
|
||||||
myApp = App
|
myApp = App
|
||||||
{ appDraw = myAppDraw
|
{ appDraw = myAppDraw
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,3 @@
|
||||||
-- | A module containing the tree data structure for lines in the @.prof@ file
|
|
||||||
-- and some useful functions.
|
|
||||||
|
|
||||||
module Profold.LineNode
|
module Profold.LineNode
|
||||||
( LineNode(..)
|
( LineNode(..)
|
||||||
, newLineNode
|
, newLineNode
|
||||||
|
|
@ -12,27 +9,17 @@ module Profold.LineNode
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Vector as V
|
import qualified Data.Vector as V
|
||||||
|
|
||||||
-- | A line from the @.prof@ file and its children.
|
|
||||||
data LineNode = LineNode
|
data LineNode = LineNode
|
||||||
{ lineText :: T.Text
|
{ lineText :: T.Text
|
||||||
-- ^ The complete text of the line, including its indentation.
|
|
||||||
, lineChildren :: V.Vector LineNode
|
, lineChildren :: V.Vector LineNode
|
||||||
-- ^ The line's children.
|
|
||||||
, lineFolded :: Bool
|
, lineFolded :: Bool
|
||||||
-- ^ Whether the line's children are folded away.
|
|
||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
-- | Create a new 'LineNode'.
|
|
||||||
newLineNode :: T.Text -> [LineNode] -> LineNode
|
newLineNode :: T.Text -> [LineNode] -> LineNode
|
||||||
newLineNode text children = LineNode text (V.fromList children) True
|
newLineNode text children = LineNode text (V.fromList children) True
|
||||||
|
|
||||||
-- | A path (similar to a file path) referencing a node inside a 'LineNode'
|
|
||||||
-- tree.
|
|
||||||
type Path = [Int]
|
type Path = [Int]
|
||||||
|
|
||||||
-- | Convert a 'LineNode' into a flat list of itself and all visible children.
|
|
||||||
-- The list includes the 'Path' to each node. Nodes that would not be visible
|
|
||||||
-- because one of their parents is folded are not included.
|
|
||||||
flatten :: LineNode -> V.Vector (Path, LineNode)
|
flatten :: LineNode -> V.Vector (Path, LineNode)
|
||||||
flatten ln
|
flatten ln
|
||||||
| lineFolded ln = V.singleton ([], ln)
|
| lineFolded ln = V.singleton ([], ln)
|
||||||
|
|
@ -47,8 +34,6 @@ modifyAtIndex :: Int -> (a -> a) -> V.Vector a -> V.Vector a
|
||||||
-- Yes, this function looks ugly, but it's short enough that I don't care.
|
-- Yes, this function looks ugly, but it's short enough that I don't care.
|
||||||
modifyAtIndex i f v = maybe v (\a -> v V.// [(i, f a)]) (v V.!? i)
|
modifyAtIndex i f v = maybe v (\a -> v V.// [(i, f a)]) (v V.!? i)
|
||||||
|
|
||||||
-- | Modify a node at a specific location in the tree. Returns the original node
|
|
||||||
-- if no node exists at that path.
|
|
||||||
modify :: (LineNode -> LineNode) -> Path -> LineNode -> LineNode
|
modify :: (LineNode -> LineNode) -> Path -> LineNode -> LineNode
|
||||||
modify f [] ln = f ln
|
modify f [] ln = f ln
|
||||||
modify f (i:is) ln =
|
modify f (i:is) ln =
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
-- | A module for parsing command line options.
|
|
||||||
|
|
||||||
module Profold.Options
|
module Profold.Options
|
||||||
( Options(..)
|
( Options(..)
|
||||||
, options
|
, options
|
||||||
|
|
@ -7,16 +5,13 @@ module Profold.Options
|
||||||
|
|
||||||
import Options.Applicative
|
import Options.Applicative
|
||||||
|
|
||||||
-- | The command line options.
|
|
||||||
newtype Options = Options
|
newtype Options = Options
|
||||||
{ optFileName :: String
|
{ optFileName :: String
|
||||||
-- ^ Name of the @.prof@ file to open and parse.
|
|
||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
parser :: Parser Options
|
parser :: Parser Options
|
||||||
parser = Options
|
parser = Options
|
||||||
<$> strArgument (help "Path to the .prof file" <> metavar "FILE")
|
<$> strArgument (help "Path to the .prof file" <> metavar "FILE")
|
||||||
|
|
||||||
-- | A parser for the command line options.
|
|
||||||
options :: ParserInfo Options
|
options :: ParserInfo Options
|
||||||
options = info (helper <*> parser) fullDesc
|
options = info (helper <*> parser) fullDesc
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
-- | This module contains a parser for parsing @.prof@ files.
|
|
||||||
|
|
||||||
module Profold.ParseProfFile
|
module Profold.ParseProfFile
|
||||||
( ProfFile(..)
|
( ProfFile(..)
|
||||||
, parseProfFile
|
, parseProfFile
|
||||||
|
|
@ -15,8 +13,6 @@ import Text.Megaparsec.Char
|
||||||
|
|
||||||
import Profold.LineNode
|
import Profold.LineNode
|
||||||
|
|
||||||
-- | A @.prof@ file includes a few lines at the beginning that contain the
|
|
||||||
-- column names.
|
|
||||||
data ProfFile = ProfFile
|
data ProfFile = ProfFile
|
||||||
{ profInfoLines :: [T.Text]
|
{ profInfoLines :: [T.Text]
|
||||||
, profNode :: LineNode
|
, profNode :: LineNode
|
||||||
|
|
@ -52,8 +48,6 @@ profFile = do
|
||||||
node <- lineNode ""
|
node <- lineNode ""
|
||||||
pure $ ProfFile info node
|
pure $ ProfFile info node
|
||||||
|
|
||||||
-- | A parser for @.prof@ files. If the file could not be parsed, returns a
|
|
||||||
-- @Left errorMessage@.
|
|
||||||
parseProfFile :: String -> T.Text -> Either String ProfFile
|
parseProfFile :: String -> T.Text -> Either String ProfFile
|
||||||
parseProfFile filename text = case parse profFile filename text of
|
parseProfFile filename text = case parse profFile filename text of
|
||||||
Left e -> Left $ errorBundlePretty e
|
Left e -> Left $ errorBundlePretty e
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue