Skip to content

Commit

Permalink
[cliptext] update most inline formats to end with [/]
Browse files Browse the repository at this point in the history
  • Loading branch information
saulpw committed Oct 19, 2023
1 parent 9cd4230 commit cd3bdeb
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 34 deletions.
16 changes: 11 additions & 5 deletions docs/colors.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,26 @@ A color option name can also be used instead of a real color; for example, to us

options.disp_menu_fmt = "[:error]{vd.motd}"

Color changes can happen multiple times in a single string.
Use `[:]` to remove all inline coloring and revert to the base color for that interface element:
Attribute changes can happen multiple times in a single string.
Use `[/]` to clear the last inline color change, and `[:]` to clear all inline attributes:

options.disp_menu_fmt = "[:underline]Note:[:] [:error]{vd.motd}"
options.disp_menu_fmt = "[:underline]Note:[/] [:error]{vd.motd}"

What follows the `/` is not checked, so these are all valid:

[:underline]underlined text[/underline]
[:underline]also underlined[/]
[:underline]underline ends at end of string

### onclick

In addition to changing the display attributes, an `onclick` attribute can be given with this inline syntax, which specifies either a VisiData command to run, or a url to open (in `$BROWSER`), when the interface element is clicked:

options.disp_menu_fmt = "[:onclick https://jsvine.github.io/intro-to-visidata/]Click here to go to the tutorial"
options.disp_menu_fmt = "[:onclick https://jsvine.github.io/intro-to-visidata/]Click here to go to the tutorial[/]"

Or if you want a custom VisiData toolbar some of your favorite actions:

vd --disp_menu_fmt="[:onclick freq-col] freq out [:] | [:onclick quit-sheet] back [:]"
vd --disp_menu_fmt="[:onclick freq-col] freq out [/] | [:onclick quit-sheet] back [/]"

Elements with `onclick` are displayed with `color_clickable`, which is by default `underline`, which is commonly understood as a clickable affordance.

Expand Down
4 changes: 2 additions & 2 deletions visidata/apps/vgit/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def cursorLines(self):
r = ''
for line in self.cursorRow.lines[2:]:
if line.startswith('-'):
line = '[:git_hunk_del]' + line + '[:]'
line = '[:git_hunk_del]' + line + '[/]'
elif line.startswith('+'):
line = '[:git_hunk_add]' + line + '[:]'
line = '[:git_hunk_add]' + line + '[/]'

r += line + '\n'
r = r[4:]
Expand Down
12 changes: 6 additions & 6 deletions visidata/cliptext.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,18 +266,18 @@ def clipdraw_chunks(scr, y, x, chunks, cattr:ColorAttr=ColorAttr(), w=None, clea


def _markdown_to_internal(text):
'Return markdown-formatted `text` converted to internal formatting (like `[:color]text[:]`).'
text = re.sub(r'`(.*?)`', r'[:code]\1[:]', text)
text = re.sub(r'\*\*(.*?)\*\*', r'[:bold]\1[:]', text)
text = re.sub(r'\*(.*?)\*', r'[:italic]\1[:]', text)
text = re.sub(r'\b_(.*?)_\b', r'[:underline]\1[:]', text)
'Return markdown-formatted `text` converted to internal formatting (like `[:color]text[/]`).'
text = re.sub(r'`(.*?)`', r'[:code]\1[/]', text)
text = re.sub(r'\*\*(.*?)\*\*', r'[:bold]\1[/]', text)
text = re.sub(r'\*(.*?)\*', r'[:italic]\1[/]', text)
text = re.sub(r'\b_(.*?)_\b', r'[:underline]\1[/]', text)
return text


def wraptext(text, width=80, indent=''):
'''
Word-wrap `text` and yield (formatted_line, textonly_line) for each line of at most `width` characters.
Formatting like `[:color]text[:]` is ignored for purposes of computing width, and not included in `textonly_line`.
Formatting like `[:color]text[/]` is ignored for purposes of computing width, and not included in `textonly_line`.
'''
import re

Expand Down
6 changes: 3 additions & 3 deletions visidata/experimental/guide.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# A Guide to VisiData Guides
Each guide shows you how to use a particular feature in VisiData.
[:keys]Up/Down[:] to move the row cursor
[:keys]Enter[:] to view a topic
[:keys]Backspace[:] to come back to this list of guides
[:keys]Up/Down[/] to move the row cursor
[:keys]Enter[/] to view a topic
[:keys]Backspace[/] to come back to this list of guides
'''

import re
Expand Down
6 changes: 3 additions & 3 deletions visidata/loaders/api_matrix.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'''
# Matrix Chat Sheet
A list of messages from [:underline]{sheet.sourcename}[:].
A list of messages from [:underline]{sheet.sourcename}[/].
- `Enter` to push a sheet with all the messages from [:underline]{sheet.cursorRow.room.display_name}[:].
- `a` to send a message to [:underline]{sheet.cursorRow.room.display_name}[:].
- `Enter` to push a sheet with all the messages from [:underline]{sheet.cursorRow.room.display_name}[/].
- `a` to send a message to [:underline]{sheet.cursorRow.room.display_name}[/].
'''

from visidata import vd, VisiData, Sheet, Column, ItemColumn, date, asyncthread, AttrDict, vlen, Path
Expand Down
20 changes: 10 additions & 10 deletions visidata/loaders/api_reddit.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'''# RedditSheet
- [:keys]Ctrl+O[:] to open a browser tab to [:code]{sheet.cursorRow.display_name_prefixed}[:]
- [:keys]g Ctrl+O[:] to open browser windows for {sheet.nSelectedRows} selected subreddits
- [:keys]Ctrl+O[/] to open a browser tab to [:code]{sheet.cursorRow.display_name_prefixed}[/]
- [:keys]g Ctrl+O[/] to open browser windows for {sheet.nSelectedRows} selected subreddits
- [:keys]Enter[:] to open sheet with top ~1000 submissions for [:code]{sheet.cursorRow.display_name_prefixed}[:]
- [:keys]g Enter[:] to open sheet with top ~1000 submissions for {sheet.nSelectedRows} selected subreddits
- [:keys]Enter[/] to open sheet with top ~1000 submissions for [:code]{sheet.cursorRow.display_name_prefixed}[/]
- [:keys]g Enter[/] to open sheet with top ~1000 submissions for {sheet.nSelectedRows} selected subreddits
- [:keys]ga[:] to append more subreddits matching input by name or description
- [:keys]ga[/] to append more subreddits matching input by name or description
'''

import visidata
Expand Down Expand Up @@ -196,8 +196,8 @@ def openRows(self, rows):
class RedditSubmissions(Sheet):
help = '''# Reddit Submissions
[:keys]Enter[:] to open sheet with comments for the current post
[:keys]ga[:] to add posts in this subreddit matching input'''
[:keys]Enter[/] to open sheet with comments for the current post
[:keys]ga[/] to add posts in this subreddit matching input'''

# source=ListingGenerator
rowtype='reddit posts' # rowdef: praw.Submission
Expand Down Expand Up @@ -254,14 +254,14 @@ class RedditGuide(RedditSubmissions):
help = '''# Authenticate Reddit
The Reddit API must be configured before use.
1. Login to Reddit and go to [:underline]https://www.reddit.com/prefs/apps[:].
2. Create a "script" app. (Use "[:underline]http://localhost:8000[:]" for the redirect uri)
1. Login to Reddit and go to [:underline]https://www.reddit.com/prefs/apps[/].
2. Create a "script" app. (Use "[:underline]http://localhost:8000[/]" for the redirect uri)
3. Add credentials to visidatarc:
options.reddit_client_id = '...' # below the description in the upper left
options.reddit_client_secret = '...'
## Use [:code]reddit[:] filetype for subreddits or users
## Use [:code]reddit[/] filetype for subreddits or users
Multiple may be specified, joined with "+".
Expand Down
2 changes: 1 addition & 1 deletion visidata/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def drawMenu(vd, scr, sheet):
else:
cattr = colors.color_menu

menutitle = ' ' + ''.join(f'[:underline]{ch}[:]' if ch.isupper() else ch for ch in item.title) + ' '
menutitle = ' ' + ''.join(f'[:underline]{ch}[/]' if ch.isupper() else ch for ch in item.title) + ' '
menudraw(scr, 0, x, menutitle, cattr)

vd.onMouse(scr, x, 0, dispwidth(item.title)+2, 1,
Expand Down
2 changes: 1 addition & 1 deletion visidata/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class DirSheet(Sheet):
- `Enter` to open a file as a separate sheet
- `g Enter` to open all selected files, each in a separate sheet
- [:bold]`[:] to push the parent folder
- [:bold]`[/] to push the parent folder
- `Ctrl+O` to open the current file in your system editor
## Options (must reload to take effect)
Expand Down
2 changes: 1 addition & 1 deletion visidata/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def drawSidebar(vd, scr, sheet):
sidebar_title = ''
sidebar = vd.recentStatusMessages
bottommsg = ''
overflowmsg = '[:reverse] Ctrl+P to view all status messages [:]'
overflowmsg = '[:reverse] Ctrl+P to view all status messages [/]'
try:
if not sidebar:
sidebar = sheet.sidebar
Expand Down
5 changes: 4 additions & 1 deletion visidata/statusbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ def recentStatusMessages(vd):
elif pri == 1: msgattr = '[:warning]'
else: msgattr = ''

r += f'\n{msgattr}{msg}[/]'
if msgattr:
r += '\n' + f'{msgattr}{msg}[/]'
else:
r += '\n' + msg

if r:
return '# statuses' + r
Expand Down
2 changes: 1 addition & 1 deletion visidata/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def checkMemoryUsage(vd):
curses.flash()
else:
attr = '[:working]'
return attr + ret + '[:]'
return attr + ret + '[/]'


# for progress bar
Expand Down

0 comments on commit cd3bdeb

Please sign in to comment.