0 | module Qutescript.Command
  1 |
  2 | import Data.String
  3 |
  4 | %default total
  5 |
  6 | public export
  7 | data Key : Type where
  8 |   Chr    : Char -> Key
  9 |   Tab    : Key
 10 |   Esc    : Key
 11 |   Return : Key
 12 |
 13 | export
 14 | Interpolation Key where
 15 |   interpolate (Chr c) = singleton c
 16 |   interpolate Tab     = "<Tab>"
 17 |   interpolate Esc     = "<Esc>"
 18 |   interpolate Return  = "<Return>"
 19 |
 20 | public export
 21 | FromChar Key where fromChar = Chr
 22 |
 23 | --------------------------------------------------------------------------------
 24 | --          Flags and Options
 25 | --------------------------------------------------------------------------------
 26 |
 27 | namespace Target
 28 |
 29 |   public export
 30 |   data Target : Type where
 31 |     Normal        : Target
 32 |     Tab           : Target
 33 |     BackgroundTab : Target
 34 |     Window        : Target
 35 |
 36 |   export
 37 |   Interpolation Target where
 38 |     interpolate Normal        = ""
 39 |     interpolate Tab           = "--tab"
 40 |     interpolate BackgroundTab = "--bg"
 41 |     interpolate Window        = "--window"
 42 |
 43 |   export
 44 |   tgt : Target -> String
 45 |   tgt Normal        = "normal"
 46 |   tgt Tab           = "tab"
 47 |   tgt BackgroundTab = "tab-bg"
 48 |   tgt Window        = "window"
 49 |
 50 | public export
 51 | data Privacy = Private | NotPrivate
 52 |
 53 | export
 54 | Interpolation Privacy where
 55 |   interpolate Private    = "--private"
 56 |   interpolate NotPrivate = ""
 57 |
 58 | public export
 59 | data Security = Secure | NotSecure
 60 |
 61 | export
 62 | Interpolation Security where
 63 |   interpolate Secure    = "--secure"
 64 |   interpolate NotSecure = ""
 65 |
 66 | public export
 67 | data Rel = Related | NotRelated
 68 |
 69 | export
 70 | Interpolation Rel where
 71 |   interpolate Related    = "--related"
 72 |   interpolate NotRelated = ""
 73 |
 74 | public export
 75 | data Globality = Global | NotGlobal
 76 |
 77 | export
 78 | Interpolation Globality where
 79 |   interpolate Global    = "--global"
 80 |   interpolate NotGlobal = ""
 81 |
 82 |
 83 | --------------------------------------------------------------------------------
 84 | --          Command
 85 | --------------------------------------------------------------------------------
 86 |
 87 | public export
 88 | data Command : Type where
 89 |   Back         : Target -> Command
 90 |   ClickElement : Target -> (filter,value : String) -> Command
 91 |   Close        : Command
 92 |   FakeKeys     : Globality -> List Key -> Command
 93 |   Forward      : Target -> Command
 94 |   Help         : Target -> (topic : String) -> Command
 95 |   InsertText   : String -> Command
 96 |   Open         : Target -> Rel -> Privacy -> Security -> String -> Command
 97 |
 98 | public export %inline
 99 | open' : String -> Command
100 | open' = Open Normal NotRelated NotPrivate NotSecure
101 |
102 | public export %inline
103 | openIn : Target -> String -> Command
104 | openIn l = Open l NotRelated NotPrivate NotSecure
105 |
106 | public export %inline
107 | fakeKeys : List Key -> Command
108 | fakeKeys = FakeKeys NotGlobal
109 |
110 | public export %inline
111 | fakeKey : Key -> Command
112 | fakeKey = fakeKeys . pure
113 |
114 | export
115 | Interpolation Command where
116 |   interpolate (Back x)             = "back \{x}"
117 |   interpolate (ClickElement x f v) = "click-element -t \{tgt x} \{f} \{v}"
118 |   interpolate Close                = "close"
119 |   interpolate (FakeKeys g ks)      = "fake-key \{g} \{concat $ map interpolate ks}"
120 |   interpolate (Forward x)          = "forward \{x}"
121 |   interpolate (Help x t)           = "help \{x} \{t}"
122 |   interpolate (InsertText s)       = "insert-text \{s}"
123 |   interpolate (Open l r p s u)     = "open \{l} \{r} \{p} \{s} \{u}"
124 |