decorations for background and foreground colors;
authorwenzelm
Sat Mar 04 13:36:06 2017 +0100 (2017-03-04)
changeset 6510466b19d05dcee
parent 65103 0bf1836ce4b1
child 65105 1f47b92021de
decorations for background and foreground colors;
src/Pure/PIDE/rendering.scala
src/Tools/VSCode/extension/package.json
src/Tools/VSCode/extension/src/decorations.ts
src/Tools/VSCode/src/vscode_rendering.scala
     1.1 --- a/src/Pure/PIDE/rendering.scala	Sat Mar 04 13:33:47 2017 +0100
     1.2 +++ b/src/Pure/PIDE/rendering.scala	Sat Mar 04 13:36:06 2017 +0100
     1.3 @@ -14,19 +14,24 @@
     1.4  
     1.5    object Color extends Enumeration
     1.6    {
     1.7 +    // background
     1.8      val unprocessed1 = Value("unprocessed1")
     1.9      val running1 = Value("running1")
    1.10      val bad = Value("bad")
    1.11      val intensify = Value("intensify")
    1.12      val entity = Value("entity")
    1.13 -    val quoted = Value("quoted")
    1.14 -    val antiquoted = Value("antiquoted")
    1.15      val active = Value("active")
    1.16      val active_result = Value("active_result")
    1.17      val markdown_item1 = Value("markdown_item1")
    1.18      val markdown_item2 = Value("markdown_item2")
    1.19      val markdown_item3 = Value("markdown_item3")
    1.20      val markdown_item4 = Value("markdown_item4")
    1.21 +    val background = values
    1.22 +
    1.23 +    // foreground
    1.24 +    val quoted = Value("quoted")
    1.25 +    val antiquoted = Value("antiquoted")
    1.26 +    val foreground = values -- background
    1.27    }
    1.28  
    1.29  
     2.1 --- a/src/Tools/VSCode/extension/package.json	Sat Mar 04 13:33:47 2017 +0100
     2.2 +++ b/src/Tools/VSCode/extension/package.json	Sat Mar 04 13:36:06 2017 +0100
     2.3 @@ -67,7 +67,33 @@
     2.4                      "items": { "type": "string" },
     2.5                      "default": [],
     2.6                      "description": "Command-line arguments for isabelle vscode_server process."
     2.7 -                }
     2.8 +                },
     2.9 +                "isabelle.unprocessed1_light_color": { "type": "string", "default": "rgba(255, 160, 160, 0.20)" },
    2.10 +                "isabelle.unprocessed1_dark_color": { "type": "string", "default": "rgba(255, 160, 160, 0.20)" },
    2.11 +                "isabelle.running1_light_color": { "type": "string", "default": "rgba(97, 0, 97, 0.39)" },
    2.12 +                "isabelle.running1_dark_color": { "type": "string", "default": "rgba(97, 0, 97, 0.39)" },
    2.13 +                "isabelle.bad_light_color": { "type": "string", "default": "rgba(255, 106, 106, 0.39)" },
    2.14 +                "isabelle.bad_dark_color": { "type": "string", "default": "rgba(255, 106, 106, 0.39)" },
    2.15 +                "isabelle.intensify_light_color": { "type": "string", "default": "rgba(255, 204, 102, 0.39)" },
    2.16 +                "isabelle.intensify_dark_color": { "type": "string", "default": "rgba(255, 204, 102, 0.39)" },
    2.17 +                "isabelle.entity_light_color": { "type": "string", "default": "rgba(204, 217, 255, 0.50)" },
    2.18 +                "isabelle.entity_dark_color": { "type": "string", "default": "rgba(204, 217, 255, 0.50)" },
    2.19 +                "isabelle.active_light_color": { "type": "string", "default": "rgba(220, 220, 220, 1.00)" },
    2.20 +                "isabelle.active_dark_color": { "type": "string", "default": "rgba(220, 220, 220, 1.00)" },
    2.21 +                "isabelle.active_result_light_color": { "type": "string", "default": "rgba(153, 153, 102, 1.00)" },
    2.22 +                "isabelle.active_result_dark_color": { "type": "string", "default": "rgba(153, 153, 102, 1.00)" },
    2.23 +                "isabelle.markdown_item1_light_color": { "type": "string", "default": "rgba(218, 254, 218, 1.00)" },
    2.24 +                "isabelle.markdown_item1_dark_color": { "type": "string", "default": "rgba(218, 254, 218, 1.00)" },
    2.25 +                "isabelle.markdown_item2_light_color": { "type": "string", "default": "rgba(255, 240, 204, 1.00)" },
    2.26 +                "isabelle.markdown_item2_dark_color": { "type": "string", "default": "rgba(255, 240, 204, 1.00)" },
    2.27 +                "isabelle.markdown_item3_light_color": { "type": "string", "default": "rgba(231, 231, 255, 1.00)" },
    2.28 +                "isabelle.markdown_item3_dark_color": { "type": "string", "default": "rgba(231, 231, 255, 1.00)" },
    2.29 +                "isabelle.markdown_item4_light_color": { "type": "string", "default": "rgba(255, 224, 240, 1.00)" },
    2.30 +                "isabelle.markdown_item4_dark_color": { "type": "string", "default": "rgba(255, 224, 240, 1.00)" },
    2.31 +                "isabelle.quoted_light_color": { "type": "string", "default": "rgba(139, 139, 139, 0.10)" },
    2.32 +                "isabelle.quoted_dark_color": { "type": "string", "default": "rgba(139, 139, 139, 0.10)" },
    2.33 +                "isabelle.antiquoted_light_color": { "type": "string", "default": "rgba(255, 200, 50, 0.10)" },
    2.34 +                "isabelle.antiquoted_dark_color": { "type": "string", "default": "rgba(255, 200, 50, 0.10)" }
    2.35              }
    2.36          }
    2.37      },
     3.1 --- a/src/Tools/VSCode/extension/src/decorations.ts	Sat Mar 04 13:33:47 2017 +0100
     3.2 +++ b/src/Tools/VSCode/extension/src/decorations.ts	Sat Mar 04 13:36:06 2017 +0100
     3.3 @@ -7,13 +7,36 @@
     3.4  
     3.5  /* known decoration types */
     3.6  
     3.7 -export interface Decorations
     3.8 +export const types = new Map<string, TextEditorDecorationType>()
     3.9 +
    3.10 +const background_colors = [
    3.11 +  "unprocessed1",
    3.12 +  "running1",
    3.13 +  "bad",
    3.14 +  "intensify",
    3.15 +  "entity",
    3.16 +  "quoted",
    3.17 +  "antiquoted",
    3.18 +  "active",
    3.19 +  "active_result",
    3.20 +  "markdown_item1",
    3.21 +  "markdown_item2",
    3.22 +  "markdown_item3",
    3.23 +  "markdown_item4"
    3.24 +]
    3.25 +
    3.26 +const foreground_colors = [
    3.27 +  "quoted",
    3.28 +  "antiquoted"
    3.29 +]
    3.30 +
    3.31 +function property(prop: string, config: string): Object
    3.32  {
    3.33 -  bad: TextEditorDecorationType
    3.34 +  let res = {}
    3.35 +  res[prop] = vscode.workspace.getConfiguration("isabelle").get<string>(config)
    3.36 +  return res
    3.37  }
    3.38  
    3.39 -export let types: Decorations
    3.40 -
    3.41  export function init(context: ExtensionContext)
    3.42  {
    3.43    function decoration(options: DecorationRenderOptions): TextEditorDecorationType
    3.44 @@ -23,11 +46,22 @@
    3.45      return typ
    3.46    }
    3.47  
    3.48 -  if (!types)
    3.49 -    types =
    3.50 -    {
    3.51 -      bad: decoration({ backgroundColor: 'rgba(255, 106, 106, 0.4)' })
    3.52 -    }
    3.53 +  function background(color: string): TextEditorDecorationType
    3.54 +  {
    3.55 +    const prop = "backgroundColor"
    3.56 +    const light = property(prop, color.concat("_light_color"))
    3.57 +    const dark = property(prop, color.concat("_dark_color"))
    3.58 +    return decoration({ light: light, dark: dark })
    3.59 +  }
    3.60 +
    3.61 +  types.clear
    3.62 +  for (let color of background_colors) {
    3.63 +    types["background_".concat(color)] = background(color)
    3.64 +  }
    3.65 +  for (let color of foreground_colors) {
    3.66 +    types["foreground_".concat(color)] = background(color) // approximation
    3.67 +  }
    3.68 +  types["bad"] = decoration({})
    3.69  }
    3.70  
    3.71  
     4.1 --- a/src/Tools/VSCode/src/vscode_rendering.scala	Sat Mar 04 13:33:47 2017 +0100
     4.2 +++ b/src/Tools/VSCode/src/vscode_rendering.scala	Sat Mar 04 13:36:06 2017 +0100
     4.3 @@ -15,6 +15,25 @@
     4.4  
     4.5  object VSCode_Rendering
     4.6  {
     4.7 +  /* decorations */
     4.8 +
     4.9 +  def color_decorations(prefix: String, types: Rendering.Color.ValueSet,
    4.10 +    colors: List[Text.Info[Rendering.Color.Value]]): List[Document_Model.Decoration] =
    4.11 +  {
    4.12 +    val color_ranges =
    4.13 +      (Map.empty[Rendering.Color.Value, List[Text.Range]] /: colors) {
    4.14 +        case (m, Text.Info(range, c)) => m + (c -> (range :: m.getOrElse(c, Nil)))
    4.15 +      }
    4.16 +    for (c <- types.toList)
    4.17 +    yield {
    4.18 +      val typ = prefix + c.toString
    4.19 +      val content =
    4.20 +        color_ranges.getOrElse(c, Nil).reverse.map(r => Text.Info(r, Nil: XML.Body))
    4.21 +      Document_Model.Decoration(typ, content)
    4.22 +    }
    4.23 +  }
    4.24 +
    4.25 +
    4.26    /* diagnostic messages */
    4.27  
    4.28    private val message_severity =
    4.29 @@ -97,13 +116,21 @@
    4.30    /* decorations */
    4.31  
    4.32    def decorations: List[Document_Model.Decoration] =
    4.33 -    List(Document_Model.Decoration(Protocol.Decorations.bad, decorations_bad))
    4.34 +    decorations_bad :::
    4.35 +    VSCode_Rendering.color_decorations("background_", Rendering.Color.background,
    4.36 +      background(model.content.text_range, Set.empty)) :::
    4.37 +    VSCode_Rendering.color_decorations("foreground_", Rendering.Color.foreground,
    4.38 +      foreground(model.content.text_range))
    4.39  
    4.40 -  def decorations_bad: List[Text.Info[XML.Body]] =
    4.41 -    snapshot.select(model.content.text_range, VSCode_Rendering.bad_elements, _ =>
    4.42 -      {
    4.43 -        case Text.Info(_, XML.Elem(_, body)) => Some(body)
    4.44 -      })
    4.45 +  def decorations_bad: List[Document_Model.Decoration] =
    4.46 +  {
    4.47 +    val content =
    4.48 +      snapshot.select(model.content.text_range, VSCode_Rendering.bad_elements, _ =>
    4.49 +        {
    4.50 +          case Text.Info(_, XML.Elem(_, body)) => Some(body)
    4.51 +        })
    4.52 +    List(Document_Model.Decoration(Protocol.Decorations.bad, content))
    4.53 +  }
    4.54  
    4.55    def decoration_output(decoration: Document_Model.Decoration): Protocol.Decoration =
    4.56    {