Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

[#5] Create first draft of Tui with sample process #8

Merged
merged 4 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Test where

import Brick

ui :: Widget ()
ui = str "Sup world"

main :: IO ()
main = simpleMain ui
6 changes: 4 additions & 2 deletions app/Main.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Main where

import qualified ProtoRoute
-- import qualified ProtoRoute
import qualified Tui

main :: IO ()
main = ProtoRoute.main
-- main = ProtoRoute.main
main = Tui.main
15 changes: 12 additions & 3 deletions proto-route.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extra-doc-files: README.md
, CHANGELOG.md
cabal-version: 1.24
tested-with: GHC == 8.4.3
extra-source-files: proto/protobuf1.proto
extra-source-files: proto/*.proto

source-repository head
type: git
Expand All @@ -33,16 +33,21 @@ library
ProtoRoute
ProtoRoute.Ghcid
ProtoRoute.Message
Proto.Protobuf1
Proto.Protobuf1_Fields
Proto.Protobuf2
Proto.Protobuf2_Fields
Tui
ghc-options: -Wall
build-depends: base >=4.7 && <5
, brick
, containers
, directory
, ghcid
, linear
, protobuf
, proto-lens
, proto-lens-protoc
, text
, vty
default-language: Haskell2010


Expand All @@ -51,11 +56,15 @@ executable proto-route
main-is: Main.hs
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, brick
, containers
, directory
, ghcid
, linear
, protobuf
, proto-lens
, proto-lens-protoc
, proto-route
, text
, vty
default-language: Haskell2010
1 change: 0 additions & 1 deletion proto/protobuf1.proto → proto/protobuf2.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ syntax = "proto2";

message SearchRequest {
required string query = 1;
optional string browser = 2;
}
177 changes: 177 additions & 0 deletions report.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
<title>HLint Report</title>
<script type='text/javascript'>

/* == Algorithm for show/unshow ==
Each hint/file is given a number, hint# or file#
When we say showOnly with a class name we add the rules to
the css #content div {display:none}, #content div.className {display:block}
When going back to showAll we remove these results
*/

// CSS MANIPULATION //

function deleteRules(n)
{
var css = document.styleSheets[0];
for (var i = 0; i < n; i++)
css.deleteRule(css.cssRules.length-1);
}

function insertRule(s)
{
var css = document.styleSheets[0];
css.insertRule(s, css.cssRules.length);
}

// SHOW/HIDE LOGIC //

var last = "";

function show(id)
{
if (id == last) return;
if (id == "")
{
deleteRules(3);
insertRule(".all {font-weight: bold;}");
}
else
{
if (last == "")
{
deleteRules(1);
insertRule("#content div {display:none;}");
}
else
{
deleteRules(2);
}
insertRule("#content div." + id + " {display:block;}");
insertRule("#" + id + "{font-weight:bold;}");
}

last = id;
}

</script>
<style type="text/css">
/* These rules are manipulated by the script.
The commented form is how it looks with an id selected */

.all {font-weight: bold;} /* #content div {display:none;} */
/* #content div.id {display:block;} */
/* #id {font-weight: bold;} */

</style>
<style type="text/css">
/* See http://www.webreference.com/programming/css_frames/ */
body {
margin:0;
border:0;
padding:0;
height:100%;
max-height:100%;
font-family: sans-serif;
font-size:76%;
overflow: hidden;
}

#leftbar {
position:absolute;
top:0px;
left:0px;
width: 215px;
bottom: 0px;
overflow:auto;
background:rgb(202,223,255);
margin: 10px;
padding-top: 0;
padding-left: 7px;
padding-right: 7px;
border-radius: 5px;

display:none; /* Override if script present */
}

#content {
position:absolute;
top:0;
bottom:0;
right:0;
overflow:auto;
padding-bottom: 15px;
padding-right: 7px;

left:10px; /* Override if script present */
}

#leftbar ul {margin-top: 0px; padding-left: 15px;}
#leftbar p {margin-bottom: 0px;}
.note {color: gray; font-size: smaller;}

pre {
font-family: "lucida console", monospace;
padding-left: 15px;
margin: 2px;
}

#content div {
margin-bottom: 10px;
margin-right: 10px;
padding-top: 4px;
border-top: 1px solid #ccc;
}

.script #content {left:250px;}
.script #leftbar {display: block;}

/* From HsColour */
.hs-keyglyph, .hs-layout {color: red;}
.hs-keyword {color: blue;}
.hs-comment, .hs-comment a {color: green;}
.hs-str, .hs-chr {color: teal;}
</style>
</head>
<body>

<script type='text/javascript'>
document.body.className = "script";
</script>

<div id="leftbar" valign="top" style="min-width:200px">

<p><a class="all" href="javascript:show('')">All hints</a></p>
<ul>
<li><a id="hint0" href="javascript:show('hint0')">Error: Parse error (1)</a></li>
</ul>

<p><a class="all" href="javascript:show('')">All files</a></p>
<ul>
<li><a id="file0" href="javascript:show('file0')">src/Tui.hs (1)</a></li>
</ul>

</div>
<div id="content" valign="top" width="100%">
<p>
Report generated by <a href="http://community.haskell.org/~ndm/hlint/">HLint</a>
v2.1.8
- a tool to suggest improvements to your Haskell code.
</p>

<div class="hint0 file0">
src/Tui.hs:68:1: Error: Parse error<br/>
Found<br/>
<pre> <span class='hs-varid'>simpleMain</span> <span class='hs-varid'>setFieldName</span>
<span class='hs-varid'>fieldName</span> <span class='hs-keyglyph'>&lt;-</span> <span class='hs-varid'>getLine</span>
<span class='hs-varop'>&gt;</span>
</pre>

</div>

</div>
</body>
</html>
8 changes: 4 additions & 4 deletions src/ProtoExports.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ProtoExports
( module Proto.Protobuf1
, module Proto.Protobuf1_Fields
( module Proto.Protobuf2
, module Proto.Protobuf2_Fields
) where

import Proto.Protobuf1
import Proto.Protobuf1_Fields
import Proto.Protobuf2
import Proto.Protobuf2_Fields
1 change: 1 addition & 0 deletions src/ProtoRoute/Ghcid.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ runGhci stuff = do
runCmd ":set -XOverloadedStrings"
runCmd "import Data.ProtoLens.Encoding"
runCmd ":load src/ProtoExports"
putStrLn stuff
runCmd ("let testMsg = " ++ stuff)
runCmd "encodeMessage testMsg"
stopGhci g
4 changes: 2 additions & 2 deletions src/ProtoRoute/Message.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ import Data.Text (Text)
newtype MsgName = MN { unMsgName :: String } deriving newtype (Show)
newtype FieldName = FN { unFieldName :: String } deriving newtype (Show)

data TValue a = Req a | Opt (Maybe a) | Rep [a] deriving (Show) -- value type
data TValue a = Req a | Opt (Maybe a) | Rep [a] | Error deriving (Show)
data FieldValue = FText (TValue Text) | FInt (TValue Int) |
FMsg (TValue Message) deriving (Show)
-- Typesafe representation of a protobuf mesage
data Message = Message
{ messageName :: MsgName
, messageFields :: [(FieldName, FieldValue)]
Expand All @@ -40,6 +39,7 @@ fromTV :: (Show a) => TValue a -> String
fromTV (Req val) = show val
fromTV (Opt txt) = show txt
fromTV (Rep list) = show list
fromTV Error = "Error"

constructProtoMsg :: MsgName -> [(FieldName, FieldValue)] -> String
constructProtoMsg msgName namesVals =
Expand Down
Loading