SlideShare a Scribd company logo
1 of 15
Download to read offline
completion_proc
no6v (Nobuhiro IMAI)
   RubyKansai
  Sat, 21 Jul 2012
require "readline"
     line edit (←→)
     history (↑↓)
     completion (Tab)



01                      14
line edit
     Readline.readline("⚡ ")

     ⚡ ←→



02                             14
history
     Readline.readline("⚡ ", true)

     ⚡   Readline::HISTORY.clear
     ⚡   Readline::HISTORY << "a"
     ⚡   Readline::HISTORY << "b"
     ⚡   ↑↓


03                                   14
completion
     Readline.completion_proc
     Readline.completion_proc =
       ->(word){%w[word1 word2 ...]}




04                                     14
demo
demo
memo of demo
     github.com/jugyo/earthquake
     github.com/no6v/
     rubykansai55/blob/master/
     completion_proc.rb


06                                 14
fat man in readline
     puts Readline.
       methods(false).
       grep(->m{/[=?]$/!~m}).
       sort_by(&:size).
       reverse
     # refs hp12c http://bit.ly/QnKcDS



07                                       14
GJ! Thanks!! http://bit.ly/QnFG8r


08                               14
break
break
Array-like object
     Readline::HISTORY.class # => Object
     Readline::HISTORY.singleton_methods(false) # =>
      [:to_s, :[], :[]=, :<<, :push, :pop,
       :shift, :each, :length, :size, :empty?,
       :delete_at, :clear]
     Enumerable === Readline::HISTORY # => true




10                                                     14
but, somethings lack...
     unshift(*obj)
     last
      first(n)/last(n)

     delete_if{|x| ... }


11                         14
HISTORY.delete_if
     require "readline"

     class << Readline::HISTORY
       def delete_if(&block)
         return enum_for(__method__) unless block
         raise SecurityError if $SAFE == 4
         i = 0
         while (size > i) do
           break unless entry = self[i]
           if block.call(entry)
             delete_at(i)
           else
             i += 1
           end
         end
         return self
       end
     end



12                                                  14
hist_delete_if
     static VALUE
     hist_delete_if(VALUE self)
     {
       HIST_ENTRY *entry;
       int i = 0;

         RETURN_ENUMERATOR(self, 0, 0);

         rb_secure(4);
         while (history_length > i) {
           entry = history_get(history_get_offset_func(i));
           if (entry == NULL) break;
           if (RTEST(rb_yield(rb_locale_str_new_cstr(entry->line))))
             rb_remove_history(i);
           else
             i++;
         }
         return self;
     }




13                                                                     14
Thanks & Q?
Thanks & Q?

More Related Content

What's hot (20)

Duralexsedregex
DuralexsedregexDuralexsedregex
Duralexsedregex
 
Vcs23
Vcs23Vcs23
Vcs23
 
Chat code
Chat codeChat code
Chat code
 
プログラム実行の話と
OSとメモリの挙動の話
プログラム実行の話と
OSとメモリの挙動の話プログラム実行の話と
OSとメモリの挙動の話
プログラム実行の話と
OSとメモリの挙動の話
 
Funcd
FuncdFuncd
Funcd
 
HailDB: A NoSQL API Direct to InnoDB
HailDB: A NoSQL API Direct to InnoDBHailDB: A NoSQL API Direct to InnoDB
HailDB: A NoSQL API Direct to InnoDB
 
20151224-games
20151224-games20151224-games
20151224-games
 
システムコールトレーサーの動作原理と実装 (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)
 
Thread介紹
Thread介紹Thread介紹
Thread介紹
 
dplyr
dplyrdplyr
dplyr
 
2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js
 
What is python
What is pythonWhat is python
What is python
 
Sol8
Sol8Sol8
Sol8
 
为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?
 
Azure Durable Funkiness - .NET Oxford June 2018
Azure Durable Funkiness - .NET Oxford June 2018Azure Durable Funkiness - .NET Oxford June 2018
Azure Durable Funkiness - .NET Oxford June 2018
 
Sol9
Sol9Sol9
Sol9
 
JavaScript Code Formatting With Prettier by Christopher Chedeau
JavaScript Code Formatting With Prettier by Christopher ChedeauJavaScript Code Formatting With Prettier by Christopher Chedeau
JavaScript Code Formatting With Prettier by Christopher Chedeau
 
Vcs8
Vcs8Vcs8
Vcs8
 
Yg byev2e
Yg byev2eYg byev2e
Yg byev2e
 
File Handling Program
File Handling ProgramFile Handling Program
File Handling Program
 

Viewers also liked

Collecting user input
Collecting user inputCollecting user input
Collecting user inputPeter Andrews
 
Proyecto 1: Aprendiendo sobre las TIC's
Proyecto 1: Aprendiendo sobre las TIC'sProyecto 1: Aprendiendo sobre las TIC's
Proyecto 1: Aprendiendo sobre las TIC'sAndrés Tortós
 
BBV Theme Project + SVN Tutorial
BBV Theme Project + SVN TutorialBBV Theme Project + SVN Tutorial
BBV Theme Project + SVN TutorialDiki Andeas
 
Digital Divide & Generation Y
Digital Divide & Generation YDigital Divide & Generation Y
Digital Divide & Generation YDiki Andeas
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on RailsDiki Andeas
 
Bilmeyenler icin eskrim
Bilmeyenler icin eskrimBilmeyenler icin eskrim
Bilmeyenler icin eskrimjohnaydin
 
DevLOVE ターミナル勉強会 zsh + screen
DevLOVE ターミナル勉強会 zsh + screenDevLOVE ターミナル勉強会 zsh + screen
DevLOVE ターミナル勉強会 zsh + screenYozo SATO
 
zshと仮想端末マネージャで快適ターミナル生活
zshと仮想端末マネージャで快適ターミナル生活zshと仮想端末マネージャで快適ターミナル生活
zshと仮想端末マネージャで快適ターミナル生活Nobutoshi Ogata
 
Pengenalan Android
Pengenalan AndroidPengenalan Android
Pengenalan AndroidDiki Andeas
 
earthquake.gem or readline.so
earthquake.gem or readline.soearthquake.gem or readline.so
earthquake.gem or readline.soNobuhiro IMAI
 

Viewers also liked (12)

Collecting user input
Collecting user inputCollecting user input
Collecting user input
 
Proyecto 1: Aprendiendo sobre las TIC's
Proyecto 1: Aprendiendo sobre las TIC'sProyecto 1: Aprendiendo sobre las TIC's
Proyecto 1: Aprendiendo sobre las TIC's
 
Opencomic
OpencomicOpencomic
Opencomic
 
BBV Theme Project + SVN Tutorial
BBV Theme Project + SVN TutorialBBV Theme Project + SVN Tutorial
BBV Theme Project + SVN Tutorial
 
Digital Divide & Generation Y
Digital Divide & Generation YDigital Divide & Generation Y
Digital Divide & Generation Y
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
 
Bilmeyenler icin eskrim
Bilmeyenler icin eskrimBilmeyenler icin eskrim
Bilmeyenler icin eskrim
 
20110912 devlove
20110912 devlove20110912 devlove
20110912 devlove
 
DevLOVE ターミナル勉強会 zsh + screen
DevLOVE ターミナル勉強会 zsh + screenDevLOVE ターミナル勉強会 zsh + screen
DevLOVE ターミナル勉強会 zsh + screen
 
zshと仮想端末マネージャで快適ターミナル生活
zshと仮想端末マネージャで快適ターミナル生活zshと仮想端末マネージャで快適ターミナル生活
zshと仮想端末マネージャで快適ターミナル生活
 
Pengenalan Android
Pengenalan AndroidPengenalan Android
Pengenalan Android
 
earthquake.gem or readline.so
earthquake.gem or readline.soearthquake.gem or readline.so
earthquake.gem or readline.so
 

Similar to completion_proc and history

Similar to completion_proc and history (9)

Python 1 liners
Python 1 linersPython 1 liners
Python 1 liners
 
Marat-Slides
Marat-SlidesMarat-Slides
Marat-Slides
 
3
33
3
 
Message in a bottle
Message in a bottleMessage in a bottle
Message in a bottle
 
Kotlin
KotlinKotlin
Kotlin
 
What's New In C# 7
What's New In C# 7What's New In C# 7
What's New In C# 7
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Groovy
GroovyGroovy
Groovy
 
C++ idioms.pptx
C++ idioms.pptxC++ idioms.pptx
C++ idioms.pptx
 

Recently uploaded

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

completion_proc and history

  • 1. completion_proc no6v (Nobuhiro IMAI) RubyKansai Sat, 21 Jul 2012
  • 2. require "readline" line edit (←→) history (↑↓) completion (Tab) 01 14
  • 3. line edit Readline.readline("⚡ ") ⚡ ←→ 02 14
  • 4. history Readline.readline("⚡ ", true) ⚡ Readline::HISTORY.clear ⚡ Readline::HISTORY << "a" ⚡ Readline::HISTORY << "b" ⚡ ↑↓ 03 14
  • 5. completion Readline.completion_proc Readline.completion_proc = ->(word){%w[word1 word2 ...]} 04 14
  • 7. memo of demo github.com/jugyo/earthquake github.com/no6v/ rubykansai55/blob/master/ completion_proc.rb 06 14
  • 8. fat man in readline puts Readline. methods(false). grep(->m{/[=?]$/!~m}). sort_by(&:size). reverse # refs hp12c http://bit.ly/QnKcDS 07 14
  • 11. Array-like object Readline::HISTORY.class # => Object Readline::HISTORY.singleton_methods(false) # => [:to_s, :[], :[]=, :<<, :push, :pop, :shift, :each, :length, :size, :empty?, :delete_at, :clear] Enumerable === Readline::HISTORY # => true 10 14
  • 12. but, somethings lack... unshift(*obj) last first(n)/last(n) delete_if{|x| ... } 11 14
  • 13. HISTORY.delete_if require "readline" class << Readline::HISTORY def delete_if(&block) return enum_for(__method__) unless block raise SecurityError if $SAFE == 4 i = 0 while (size > i) do break unless entry = self[i] if block.call(entry) delete_at(i) else i += 1 end end return self end end 12 14
  • 14. hist_delete_if static VALUE hist_delete_if(VALUE self) { HIST_ENTRY *entry; int i = 0; RETURN_ENUMERATOR(self, 0, 0); rb_secure(4); while (history_length > i) { entry = history_get(history_get_offset_func(i)); if (entry == NULL) break; if (RTEST(rb_yield(rb_locale_str_new_cstr(entry->line)))) rb_remove_history(i); else i++; } return self; } 13 14