Commit 2301e100 authored by Perceval Guillou's avatar Perceval Guillou

Merge branch 'color_the_bliss' into 'master'

fix shell color style to be white-background safe + doc

See merge request bliss/bliss!1309
parents e332c565 9a2223f6
......@@ -228,6 +228,8 @@ class BlissRepl(PythonRepl):
self.show_signature = True
self.ui_styles["bliss_ui"] = repl_style.bliss_ui_style
self.use_ui_colorscheme("bliss_ui")
# Records bliss color style and make it active in bliss shell.
self.code_styles["bliss_code"] = repl_style.bliss_code_style
self.use_code_colorscheme("bliss_code")
......
......@@ -19,6 +19,7 @@ _bliss_ui_style.update(
"signature-toolbar.operator": "bg:#44bbbb #000000 bold",
}
)
bliss_ui_style = Style.from_dict(_bliss_ui_style)
......@@ -30,13 +31,40 @@ from pygments.token import Token
_bliss_code_style = get_style_by_name("default").styles
# change #0000FF to something that works also for dark bakckgrounds
# Change some colors to have something readable on dark and light backgrounds
_bliss_code_style[Token.Name.Function] = "#0085A1"
_bliss_code_style[Token.Name.Class] = "bold #0085A1"
_bliss_code_style[Token.Name.Namespace] = "bold #0085A1"
_bliss_code_style[Token.Literal.Number] = "bold #008700"
_bliss_code_style[Token.Literal.Number] = "bold #008700"
_bliss_code_style[Token.Operator] = ""
_bliss_code_style[Token.Name.Variable] = "#AA6699" # __class__
_bliss_code_style[Token.Operator.Word] = "bold #AA6699" # and/in/not
_bliss_code_style[Token.Name.Decorator] = "#AA6699" # decorator
# Creates bliss style
bliss_code_style = pt_pygments.style_from_pygments_dict(_bliss_code_style)
"""
Example to test:
@tutu
class MyClass():
def __init__():
load_script('demod.py')
if AA and not BB:
type(e.titi)
print('\033[31;42m salut')
from NameSpace import FF
pass
def my_func():
PythonRepl.__class__();print('dddD') ; # fdslkfjsd
for ii in ['aa', 'bb', 'cc']:
print(ii)
try:
aascan(mot1,13.2+22*2/2-1)
except KeyboardInterrupt:
print('basta')
print('bye')
"""
BLISS shell
===========
# BLISS shell
Useful commands
---------------
## Useful commands
Functions that can help to customize a BLISS session.
* Current session name: `get_current().name` propertie.
Example:
```python
from bliss.common import session
session.get_current().name
```
## Color scheme
* Current session name: `get_current().name`
* Beamline name: `BEAMLINE`
**NO MORE VALID**
Color scheme
------------
BLISS terminal color scheme can be changed by adding to the config
file (`sessions/scripts/<session>.py`) of the session:
```python
from bliss.shell.cli.repl import REPL as repl
repl.use_code_colorscheme('pastie')
```
BLISS terminal color scheme can be changed by adding :
To list available color schemes:
```python
import pygments
list(pygments.styles.get_all_styles())
```
repl.use_code_colorscheme('pastie')
to the config file (`sessions/scripts/<session>.py`) of the session.
### Color schemes
example :
from bliss.shell.cli import configure
@configure
def config(repl):
repl.bliss_bar.items.append(LabelWidget("BL=ID42c"))
## Terminal scrolling
# Color scheme change.
repl.use_code_colorscheme('pastie')
**NO MORE VALID**
Terminal scrolling
------------------
Symptom: Can not scroll up in the BLISS session terminal
......@@ -47,8 +52,10 @@ a return to the the last line.
Click on `Close` and "Voila !"
Toolbar customization
---------------------
## Toolbar customization
**NO MORE VALID**
To customize the toolbar of a session, special **Widgets** can be
defined and inserted into the toolbar item list.
......@@ -68,59 +75,66 @@ A **generic widget** can also be used with a custom function.
Example to add a simple label, the position of a motor and a function to display time:
from bliss.shell.cli import configure
from bliss.shell.cli.layout import AxisStatus, LabelWidget, DynamicWidget
from bliss.shell.cli.esrf import Attribute, FEStatus, IDStatus, BEAMLINE
import time
def what_time_is_it():
return time.ctime()
@configure
def config_widgets(repl):
repl.bliss_bar.items.append(LabelWidget("BL=ID245c"))
repl.bliss_bar.items.append(AxisStatus('simot1'))
repl.bliss_bar.items.append(DynamicWidget(what_time_is_it))
```python
from bliss.shell.cli import configure
from bliss.shell.cli.layout import AxisStatus, LabelWidget, DynamicWidget
from bliss.shell.cli.esrf import Attribute, FEStatus, IDStatus, BEAMLINE
import time
def what_time_is_it():
return time.ctime()
@configure
def config_widgets(repl):
repl.bliss_bar.items.append(LabelWidget("BL=ID245c"))
repl.bliss_bar.items.append(AxisStatus('simot1'))
repl.bliss_bar.items.append(DynamicWidget(what_time_is_it))
```
This code will make a session to look like:
(bliss) pcsht:~ % bliss -s eh1
__ __ __
|__) | | /__` /__`
|__) |__ | .__/ .__/
Welcome to BLISS version 0.02 running on pcsht (in bliss Conda environment)
Copyright (c) 2015-2019 Beamline Control Unit, ESRF
-
Connected to Beacon server on pcsht (port 3412)
eh1: Executing setup...
Initializing 'simot1`
Initializing 'pzth`
Initializing 'simul_mca`
Initializing 'pzth_enc`
hello eh1 session !!
Done.
EH1 [1]:
BL=ID245c | simot1: 12.05 | Wed Apr 25 17:08:21 CEST 2018
```python
(bliss) pcsht:~ % bliss -s eh1
__ __ __
|__) | | /__` /__`
|__) |__ | .__/ .__/
More widgets can be defined using the same model:
Welcome to BLISS version 0.02 running on pcsht (in bliss Conda environment)
Copyright (c) 2015-2019 Beamline Control Unit, ESRF
-
Connected to Beacon server on pcsht (port 3412)
eh1: Executing setup...
Initializing 'simot1`
Initializing 'pzth`
Initializing 'simul_mca`
Initializing 'pzth_enc`
hello eh1 session !!
Done.
EH1 [1]:
ugap = Attribute('UGap: ', 'CPM00-1B_GAP_Position', 'mm', None)
fe_attrs = FEStatus.state, FEStatus.current, FEStatus.refill, FEStatus.mode
repl.bliss_bar.items.append(FEStatus(attributes=fe_attrs)) # Front-End infos
repl.bliss_bar.items.append(IDStatus(attributes=(ugap,))) # ID position
BL=ID245c | simot1: 12.05 | Wed Apr 25 17:08:21 CEST 2018
```
More widgets can be defined using the same model:
```python
ugap = Attribute('UGap: ', 'CPM00-1B_GAP_Position', 'mm', None)
fe_attrs = FEStatus.state, FEStatus.current, FEStatus.refill, FEStatus.mode
To switch to a more compact view (for compliant widgets like AxisStatus), use:
repl.bliss_bar.items.append(FEStatus(attributes=fe_attrs)) # Front-End infos
repl.bliss_bar.items.append(IDStatus(attributes=(ugap,))) # ID position
```
repl.bliss_bar_format = 'compact'
To switch to a more compact view (for compliant widgets like
AxisStatus), use:
```python
repl.bliss_bar_format = 'compact'
```
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment