SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Downloaden Sie, um offline zu lesen
Hello, I’m MASASHI.
Live Broadcasting Engineer in Japan.
c-bata c_bata_! "
I love Django, Pandas and prompt-toolkit ❤
How to develop
a rich terminal UI application.
#pyconmy #pyconapac2017
What is python-prompt-toolkit.
go-prompt
golang port is published at:
https://github.com/c-bata/go-prompt
1. How to receive a keyboard input
2. How to control the terminal output
Two things you need to know
when you develop a rich terminal UI app.
How to receive a keyboard input
$ cat hello.py
x = input()
print(x)
$ python3 hello.py
Hello World
Hello World
input() function
Most basic way but some special characters are interpreted

ex) Ctrl+A, Ctrl+E, F1, F2, etc…
How to receive a keyboard input
$ cat hello.py
x = input()
print(x)
$ python3 hello.py
Hello World
Hello World
input() function
Most basic way but some special characters are interpreted

ex) Ctrl+A, Ctrl+E, F1, F2, etc…
Your input interpreted some
special characters.
e.g. Ctrl+A, Ctrl+E, F1, F2, …
How to receive a keyboard input
$ cat hello.py
x = input()
print(x)
$ python3 hello.py
Hello World
Hello World
input() function
Most basic way but some special characters are interpreted

ex) Ctrl+A, Ctrl+E, F1, F2, etc…
And this way cannot receive immediately
when user press a something key.
How to receive a keyboard input
passes the data as-is to the program without interpreting

any of the special characters.
Raw mode input
See https://github.com/jonathanslenders/python-prompt-
toolkit/blob/master/prompt_toolkit/terminal/vt100_input.py
How to change the Raw Mode.
UNIX system calls tcgetattr and tcsetattr is available

for manipulating termios structure provided by termios
package in standard library.
import termios
def tty_raw(fd): # put terminal into a raw mode
buf = termios.tcgetattr(fd)
buf[3] &= ~(termios.ECHO|termios.ICANON|termios.IEXTEN|
termios.ISIG)
buf[0] &= ~(termios.BRKINT|termios.ICRNL|termios.INPCK|
termios.ISTRIP|termios.IXON)
buf[3] &= ~(termios.CSIZE|termios.PARENB)
buf[3] |= termios.CS8
buf[1] &= ~(termios.OPOST)
buf[6][termios.VMIN] = 1
buf[6][termios.VTIME] = 0
termios.tcsetattr(fd, termios.TCSAFLUSH, buf)
1. How to receive a keyboard input
2. How to control the terminal output
Two things you need to know
when you develop a rich terminal UI app.
VT100 was the first of digital terminal.

It can export bold text, italic text,

blinking text and underline in specific words.
What is “VT100 Escape Sequences”
https://en.wikipedia.org/wiki/VT100
What is “Escape Sequences”
What is “Escape Sequences”
Show underline
Change background color to Cyan
Change text color to Black
http://www.termsys.demon.co.uk/vtansi.htm
What is “Escape Sequences”
print “Hello”
What is “Escape Sequences”
Reset all attributes.
Summary
Raw mode
VT100 escape sequences
Happy terminal hacking ;)
TERIMA KASIH
Thank you for listening :)

Weitere ähnliche Inhalte

Was ist angesagt?

Phttp://www.cw360ms.com/pmsurveyresults/index.aspda
Phttp://www.cw360ms.com/pmsurveyresults/index.aspdaPhttp://www.cw360ms.com/pmsurveyresults/index.aspda
Phttp://www.cw360ms.com/pmsurveyresults/index.aspda
Hafeez Rehman
 
Porting Gentoo to DragonFly
Porting Gentoo to DragonFlyPorting Gentoo to DragonFly
Porting Gentoo to DragonFly
Naohiro Aota
 

Was ist angesagt? (20)

Instruction Combine in LLVM
Instruction Combine in LLVMInstruction Combine in LLVM
Instruction Combine in LLVM
 
D vs OWKN Language at LLnagoya
D vs OWKN Language at LLnagoyaD vs OWKN Language at LLnagoya
D vs OWKN Language at LLnagoya
 
Go Language Hands-on Workshop Material
Go Language Hands-on Workshop MaterialGo Language Hands-on Workshop Material
Go Language Hands-on Workshop Material
 
Donnez des couleurs a votre terminal
Donnez des couleurs a votre terminalDonnez des couleurs a votre terminal
Donnez des couleurs a votre terminal
 
Coding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBMCoding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBM
 
Phttp://www.cw360ms.com/pmsurveyresults/index.aspda
Phttp://www.cw360ms.com/pmsurveyresults/index.aspdaPhttp://www.cw360ms.com/pmsurveyresults/index.aspda
Phttp://www.cw360ms.com/pmsurveyresults/index.aspda
 
Introduction to go language programming
Introduction to go language programmingIntroduction to go language programming
Introduction to go language programming
 
Defer, Panic, Recover
Defer, Panic, RecoverDefer, Panic, Recover
Defer, Panic, Recover
 
Taming Rich GML with Stetl - FOSS4G 2013 Nottingham
Taming Rich GML with Stetl - FOSS4G 2013 NottinghamTaming Rich GML with Stetl - FOSS4G 2013 Nottingham
Taming Rich GML with Stetl - FOSS4G 2013 Nottingham
 
Stetl for INSPIRE Data Transformation
Stetl for INSPIRE Data TransformationStetl for INSPIRE Data Transformation
Stetl for INSPIRE Data Transformation
 
ocelot
ocelotocelot
ocelot
 
Geospatial ETL with Stetl - GeoPython 2016
Geospatial ETL with Stetl - GeoPython 2016Geospatial ETL with Stetl - GeoPython 2016
Geospatial ETL with Stetl - GeoPython 2016
 
JavaForum Nord 2021: Java to Go - Google Go für Java-Entwickler
JavaForum Nord 2021: Java to Go - Google Go für Java-EntwicklerJavaForum Nord 2021: Java to Go - Google Go für Java-Entwickler
JavaForum Nord 2021: Java to Go - Google Go für Java-Entwickler
 
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
 
Why my Go program is slow?
Why my Go program is slow?Why my Go program is slow?
Why my Go program is slow?
 
Restore
RestoreRestore
Restore
 
Script
ScriptScript
Script
 
5 Minute Intro to Stetl
5 Minute Intro to Stetl5 Minute Intro to Stetl
5 Minute Intro to Stetl
 
Porting Gentoo to DragonFly
Porting Gentoo to DragonFlyPorting Gentoo to DragonFly
Porting Gentoo to DragonFly
 
Introduction to Go language
Introduction to Go languageIntroduction to Go language
Introduction to Go language
 

Ähnlich wie How to develop a rich terminal UI application

Python-GTK
Python-GTKPython-GTK
Python-GTK
Yuren Ju
 
Lec 47.48 - stream-files
Lec 47.48 - stream-filesLec 47.48 - stream-files
Lec 47.48 - stream-files
Princess Sam
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
DRVaibhavmeshram1
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)
Yuren Ju
 

Ähnlich wie How to develop a rich terminal UI application (20)

Introduction to Python Programming | InsideAIML
Introduction to Python Programming | InsideAIMLIntroduction to Python Programming | InsideAIML
Introduction to Python Programming | InsideAIML
 
Python
PythonPython
Python
 
Python Course Basic
Python Course BasicPython Course Basic
Python Course Basic
 
slides1-introduction to python-programming.pptx
slides1-introduction to python-programming.pptxslides1-introduction to python-programming.pptx
slides1-introduction to python-programming.pptx
 
Python 3000
Python 3000Python 3000
Python 3000
 
Python PPT1.pdf
Python PPT1.pdfPython PPT1.pdf
Python PPT1.pdf
 
Python-GTK
Python-GTKPython-GTK
Python-GTK
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Lec 47.48 - stream-files
Lec 47.48 - stream-filesLec 47.48 - stream-files
Lec 47.48 - stream-files
 
Python_Haegl.powerpoint presentation. tx
Python_Haegl.powerpoint presentation. txPython_Haegl.powerpoint presentation. tx
Python_Haegl.powerpoint presentation. tx
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
Python build your security tools.pdf
Python build your security tools.pdfPython build your security tools.pdf
Python build your security tools.pdf
 
Introduction to Python.Net
Introduction to Python.NetIntroduction to Python.Net
Introduction to Python.Net
 
System programmin practical file
System programmin practical fileSystem programmin practical file
System programmin practical file
 
Class 1: Welcome to programming
Class 1: Welcome to programmingClass 1: Welcome to programming
Class 1: Welcome to programming
 
Python ppt
Python pptPython ppt
Python ppt
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)
 
UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
 
Python scripting kick off
Python scripting kick offPython scripting kick off
Python scripting kick off
 

Mehr von Masashi Shibata

MLOps Case Studies: Building fast, scalable, and high-accuracy ML systems at ...
MLOps Case Studies: Building fast, scalable, and high-accuracy ML systems at ...MLOps Case Studies: Building fast, scalable, and high-accuracy ML systems at ...
MLOps Case Studies: Building fast, scalable, and high-accuracy ML systems at ...
Masashi Shibata
 
Djangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django applicationDjangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django application
Masashi Shibata
 

Mehr von Masashi Shibata (20)

MLOps Case Studies: Building fast, scalable, and high-accuracy ML systems at ...
MLOps Case Studies: Building fast, scalable, and high-accuracy ML systems at ...MLOps Case Studies: Building fast, scalable, and high-accuracy ML systems at ...
MLOps Case Studies: Building fast, scalable, and high-accuracy ML systems at ...
 
実践Djangoの読み方 - みんなのPython勉強会 #72
実践Djangoの読み方 - みんなのPython勉強会 #72実践Djangoの読み方 - みんなのPython勉強会 #72
実践Djangoの読み方 - みんなのPython勉強会 #72
 
CMA-ESサンプラーによるハイパーパラメータ最適化 at Optuna Meetup #1
CMA-ESサンプラーによるハイパーパラメータ最適化 at Optuna Meetup #1CMA-ESサンプラーによるハイパーパラメータ最適化 at Optuna Meetup #1
CMA-ESサンプラーによるハイパーパラメータ最適化 at Optuna Meetup #1
 
サイバーエージェントにおけるMLOpsに関する取り組み at PyDataTokyo 23
サイバーエージェントにおけるMLOpsに関する取り組み at PyDataTokyo 23サイバーエージェントにおけるMLOpsに関する取り組み at PyDataTokyo 23
サイバーエージェントにおけるMLOpsに関する取り組み at PyDataTokyo 23
 
Implementing sobol's quasirandom sequence generator
Implementing sobol's quasirandom sequence generatorImplementing sobol's quasirandom sequence generator
Implementing sobol's quasirandom sequence generator
 
DARTS: Differentiable Architecture Search at 社内論文読み会
DARTS: Differentiable Architecture Search at 社内論文読み会DARTS: Differentiable Architecture Search at 社内論文読み会
DARTS: Differentiable Architecture Search at 社内論文読み会
 
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 AutumnGoptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
 
PythonとAutoML at PyConJP 2019
PythonとAutoML at PyConJP 2019PythonとAutoML at PyConJP 2019
PythonとAutoML at PyConJP 2019
 
Djangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django applicationDjangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django application
 
Django REST Framework における API 実装プラクティス | PyCon JP 2018
Django REST Framework における API 実装プラクティス | PyCon JP 2018Django REST Framework における API 実装プラクティス | PyCon JP 2018
Django REST Framework における API 実装プラクティス | PyCon JP 2018
 
Django の認証処理実装パターン / Django Authentication Patterns
Django の認証処理実装パターン / Django Authentication PatternsDjango の認証処理実装パターン / Django Authentication Patterns
Django の認証処理実装パターン / Django Authentication Patterns
 
RTMPのはなし - RTMP1.0の仕様とコンセプト / Concepts and Specification of RTMP
RTMPのはなし - RTMP1.0の仕様とコンセプト / Concepts and Specification of RTMPRTMPのはなし - RTMP1.0の仕様とコンセプト / Concepts and Specification of RTMP
RTMPのはなし - RTMP1.0の仕様とコンセプト / Concepts and Specification of RTMP
 
システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86)
システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86)システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86)
システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86)
 
Introduction of Feedy
Introduction of FeedyIntroduction of Feedy
Introduction of Feedy
 
Webフレームワークを作ってる話 #osakapy
Webフレームワークを作ってる話 #osakapyWebフレームワークを作ってる話 #osakapy
Webフレームワークを作ってる話 #osakapy
 
Pythonのすすめ
PythonのすすめPythonのすすめ
Pythonのすすめ
 
pandasによるデータ加工時の注意点やライブラリの話
pandasによるデータ加工時の注意点やライブラリの話pandasによるデータ加工時の注意点やライブラリの話
pandasによるデータ加工時の注意点やライブラリの話
 
Pythonistaのためのデータ分析入門 - C4K Meetup #3
Pythonistaのためのデータ分析入門 - C4K Meetup #3Pythonistaのためのデータ分析入門 - C4K Meetup #3
Pythonistaのためのデータ分析入門 - C4K Meetup #3
 
テスト駆動開発入門 - C4K Meetup#2
テスト駆動開発入門 - C4K Meetup#2テスト駆動開発入門 - C4K Meetup#2
テスト駆動開発入門 - C4K Meetup#2
 
Introduction of PyCon JP 2015 at PyCon APAC/Taiwan 2015
Introduction of PyCon JP 2015 at PyCon APAC/Taiwan 2015Introduction of PyCon JP 2015 at PyCon APAC/Taiwan 2015
Introduction of PyCon JP 2015 at PyCon APAC/Taiwan 2015
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

How to develop a rich terminal UI application

  • 1. Hello, I’m MASASHI. Live Broadcasting Engineer in Japan. c-bata c_bata_! " I love Django, Pandas and prompt-toolkit ❤ How to develop a rich terminal UI application. #pyconmy #pyconapac2017
  • 3. go-prompt golang port is published at: https://github.com/c-bata/go-prompt
  • 4. 1. How to receive a keyboard input 2. How to control the terminal output Two things you need to know when you develop a rich terminal UI app.
  • 5. How to receive a keyboard input $ cat hello.py x = input() print(x) $ python3 hello.py Hello World Hello World input() function Most basic way but some special characters are interpreted ex) Ctrl+A, Ctrl+E, F1, F2, etc…
  • 6. How to receive a keyboard input $ cat hello.py x = input() print(x) $ python3 hello.py Hello World Hello World input() function Most basic way but some special characters are interpreted ex) Ctrl+A, Ctrl+E, F1, F2, etc… Your input interpreted some special characters. e.g. Ctrl+A, Ctrl+E, F1, F2, …
  • 7. How to receive a keyboard input $ cat hello.py x = input() print(x) $ python3 hello.py Hello World Hello World input() function Most basic way but some special characters are interpreted ex) Ctrl+A, Ctrl+E, F1, F2, etc… And this way cannot receive immediately when user press a something key.
  • 8. How to receive a keyboard input passes the data as-is to the program without interpreting any of the special characters. Raw mode input See https://github.com/jonathanslenders/python-prompt- toolkit/blob/master/prompt_toolkit/terminal/vt100_input.py
  • 9. How to change the Raw Mode. UNIX system calls tcgetattr and tcsetattr is available for manipulating termios structure provided by termios package in standard library. import termios def tty_raw(fd): # put terminal into a raw mode buf = termios.tcgetattr(fd) buf[3] &= ~(termios.ECHO|termios.ICANON|termios.IEXTEN| termios.ISIG) buf[0] &= ~(termios.BRKINT|termios.ICRNL|termios.INPCK| termios.ISTRIP|termios.IXON) buf[3] &= ~(termios.CSIZE|termios.PARENB) buf[3] |= termios.CS8 buf[1] &= ~(termios.OPOST) buf[6][termios.VMIN] = 1 buf[6][termios.VTIME] = 0 termios.tcsetattr(fd, termios.TCSAFLUSH, buf)
  • 10. 1. How to receive a keyboard input 2. How to control the terminal output Two things you need to know when you develop a rich terminal UI app.
  • 11. VT100 was the first of digital terminal. It can export bold text, italic text, blinking text and underline in specific words. What is “VT100 Escape Sequences” https://en.wikipedia.org/wiki/VT100
  • 12. What is “Escape Sequences”
  • 13. What is “Escape Sequences” Show underline Change background color to Cyan Change text color to Black http://www.termsys.demon.co.uk/vtansi.htm
  • 14. What is “Escape Sequences” print “Hello”
  • 15. What is “Escape Sequences” Reset all attributes.
  • 16. Summary Raw mode VT100 escape sequences Happy terminal hacking ;)
  • 17. TERIMA KASIH Thank you for listening :)