You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

util.elv 832B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. use str
  2. fn abort [&code=1 a]{
  3. echo (styled $a red) >&2
  4. exit $code
  5. }
  6. fn set-title [a]{
  7. print "\e]0;"$a"\e\\"
  8. }
  9. fn merge-map [a b]{
  10. keys $b | each [k]{ a[$k] = $b[$k] }
  11. put $a
  12. }
  13. fn index-of [a b]{
  14. r = 0
  15. for val $a {
  16. if (eq $val $b) { put $r; return }
  17. r = (+ $r 1)
  18. }
  19. float64 -1
  20. }
  21. fn pad [a b &with=' ' &left=$true]{
  22. a = (to-string $a)
  23. p = (repeat (- $b (count $a)) $with | str:join '')
  24. if $left {
  25. put $p$a
  26. } else {
  27. put $a$p
  28. }
  29. }
  30. fn add-before-readline [@hooks]{
  31. for hook $hooks {
  32. if (not (has-value $edit:before-readline $hook)) {
  33. edit:before-readline=[ $@edit:before-readline $hook ]
  34. }
  35. }
  36. }
  37. fn add-after-readline [@hooks]{
  38. for hook $hooks {
  39. if (not (has-value $edit:after-readline $hook)) {
  40. edit:after-readline=[ $@edit:after-readline $hook ]
  41. }
  42. }
  43. }