sharkdp / numbat

A statically typed programming language for scientific computations with first class support for physical dimensions and units
https://numbat.dev
Apache License 2.0
1.16k stars 50 forks source link

Copy to clipboard #590

Open rben01 opened 14 hours ago

rben01 commented 14 hours ago

This is preliminary work on the copy-to-clipboard functionality that was mentioned in #394. Currently the copy command does not actually copy, but merely prints what would be copied (once I add that). In general I try to fall back to Numbat’s own defaults with user configuration where it makes sense. Here is the default config for this:

[copy-output-config.int-config]
grouping = "standard"
separator = ","
minus-sign = "-"

[copy-output-config.float-config]
max-sig-digits = 0
min-sig-digits = 0
max-width = 0
decimal = "."
capitalize-e = false

[copy-output-config.unit-config]
fancy-exponents = false
multiplication-operator = "·"
division-operator = "/"
space-btwn-operators = false

Please bike-shed away on these configuration options — names, default values, anything extraneous or missing...

With the above config (generated by numbat --generate-config), you'd get this kind of output:

>>> copy  # first command in the session
error: no value to copy
>>> 1e12

  1.0e+12

    = 1.0e+12

>>> copy
1,000,000,000,000
>>> 1kg m^2/s^2

  1 kilogram × metre² / second²

    = 1 kg·m²/s²    [Energy or Torque]

>>> copy
1 kg·m^2/s^2
>>> 

Once I do a little more work investigating what's a good clipboard crate these days I can finish this up.

rben01 commented 8 hours ago

This works only for the CLI frontend. I need to think about how to enable similar functionality for other frontends, ideally without reimplementing it from scratch — hopefully the only thing to be reimplemented would be the clipboard copying itself. Related to #584