terminal_slides 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ead5a372d8e5957d42ef6866502756a81f3a3f17f5876b4b04b97110dceef6f6
4
+ data.tar.gz: ba19ee549185cdc979f9b49560c13955c5ebcfad525b2988d044cff80ffdd9aa
5
+ SHA512:
6
+ metadata.gz: 3d63c148a389d446145a991795f7dabc0b3f2cb31d01f3b87938d25d23bd49f36ea7d9ec07c073d619c421f45d2dbd56db0870db7330aa8f6b5775a2c42dc5ae
7
+ data.tar.gz: eeafa7d02e20c893849855e7f7ae17b75158158099ee66f9c8fe813eaae4e5b62dc5429209c1277fb6bd6cd80b1170750aaee7387fb5ce89d9ac6c7f010774a6
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require "terminal_slides"
4
+
5
+
6
+ if ARGV[0].nil?
7
+ puts "File name not provided! Exiting.."
8
+ exit
9
+ end
10
+
11
+ TerminalSlides::Run.now(ARGV[0])
@@ -0,0 +1,44 @@
1
+ require "io/console"
2
+
3
+ module TerminalSlides
4
+ class Controller
5
+ def initialize(reader)
6
+ @reader = reader
7
+ @current_page = 1
8
+ end
9
+
10
+ def execute
11
+ print_current_page
12
+ catch_keys
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :reader, :current_page
18
+
19
+ def catch_keys
20
+ while true
21
+ input = $stdin.getch
22
+ case input
23
+ when "q" || "27"
24
+ exit
25
+ when "D"
26
+ if current_page != 1
27
+ @current_page -= 1
28
+ print_current_page
29
+ end
30
+ when "C"
31
+ if reader.slides.keys.max != current_page
32
+ @current_page += 1
33
+ print_current_page
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ def print_current_page
40
+ system("clear")
41
+ reader.read(current_page) { |line| reader.printer.puts(line) }
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,59 @@
1
+ require "base64"
2
+
3
+ module TerminalSlides
4
+ class Printer
5
+ FONTS = {
6
+ standard: 0,
7
+ bold: 1,
8
+ italic: 3,
9
+ underline: 4,
10
+ blink: 5,
11
+ reverse: 6
12
+ }.freeze
13
+
14
+ COLORS = {
15
+ red: 31,
16
+ green: 32,
17
+ brown: 33,
18
+ blue: 34,
19
+ magenta: 35,
20
+ cyan: 36,
21
+ gray: 37
22
+ }.freeze
23
+
24
+ BG_COLORS = {
25
+ bg_red: 41,
26
+ bg_gren: 42,
27
+ bg_brown: 43,
28
+ bg_blue: 44,
29
+ bg_magenta: 45,
30
+ bg_cyan: 46,
31
+ bg_gray: 47
32
+ }.freeze
33
+
34
+ MAPPING = {
35
+ **FONTS,
36
+ **COLORS,
37
+ **BG_COLORS
38
+ }.freeze
39
+
40
+ def set_font(font)
41
+ @font = font
42
+ end
43
+
44
+ def set_image(path)
45
+ Kernel.puts "\033]1337;File=inline=1:#{Base64.strict_encode64(File.open(path).read)}\a"
46
+ end
47
+
48
+
49
+ def puts(string)
50
+ color = font || :standard
51
+ code = MAPPING[color.to_sym] || MAPPING[:standard]
52
+ Kernel.puts("\e[#{code}m#{string}")
53
+ end
54
+
55
+ private
56
+
57
+ attr_reader :font
58
+ end
59
+ end
@@ -0,0 +1,15 @@
1
+ module TerminalSlides
2
+ class Run
3
+ def self.now(presentation_name)
4
+ begin
5
+ system("tput civis")
6
+ slides = SlideLoader.new(presentation_name).load
7
+ printer = Printer.new
8
+ reader = SlideReader.new(printer, slides)
9
+ controller = Controller.new(reader).execute
10
+ ensure
11
+ system("tput cnorm")
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,30 @@
1
+ module TerminalSlides
2
+ class SlideLoader
3
+ def initialize(file_path)
4
+ @file_path = file_path
5
+ @file_lines = { 1 => [] }
6
+ end
7
+
8
+ def load
9
+ current_page = 1
10
+ file = File.open(file_path).each do |line|
11
+ if separator?(line)
12
+ current_page += 1
13
+ file_lines[current_page] = []
14
+ else
15
+ file_lines[current_page] << line
16
+ end
17
+ end
18
+
19
+ file_lines
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :file_path, :file_lines
25
+
26
+ def separator?(line)
27
+ line.match?(/^---/)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,43 @@
1
+ module TerminalSlides
2
+ class SlideReader
3
+ def initialize(printer, slides)
4
+ @printer = printer
5
+ @slides = slides
6
+ end
7
+
8
+ def read(page)
9
+ content(page).each do |line|
10
+ parse(line)
11
+ yield(line)
12
+ end
13
+ end
14
+
15
+ def parse(line)
16
+ raw_tokens = line.scan(/{{.*}}/).flatten
17
+ tokens = raw_tokens.map { |str_token| tokenize(str_token) }
18
+ apply_tokens(tokens)
19
+
20
+ raw_tokens.each { |raw_token| line.gsub!(raw_token, "") }
21
+ end
22
+
23
+ def tokenize(str_token)
24
+ key, value = str_token.gsub(/{{|}}/, "").sub(" ", "").split(":")
25
+ end
26
+
27
+ def apply_tokens(tokens)
28
+ tokens.each do |key, value|
29
+ if printer.respond_to?("set_#{key}")
30
+ printer.send("set_#{key}", value)
31
+ end
32
+ end
33
+ end
34
+
35
+ attr_reader :printer, :slides
36
+
37
+ private
38
+
39
+ def content(page)
40
+ slides[page].map{|el| el.dup}
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,5 @@
1
+ require_relative "terminal_slides/controller"
2
+ require_relative "terminal_slides/printer"
3
+ require_relative "terminal_slides/run"
4
+ require_relative "terminal_slides/slide_loader"
5
+ require_relative "terminal_slides/slide_reader"
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: terminal_slides
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kamil Sopata
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ executables:
16
+ - terminal_slides
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - exe/terminal_slides
21
+ - lib/terminal_slides.rb
22
+ - lib/terminal_slides/controller.rb
23
+ - lib/terminal_slides/printer.rb
24
+ - lib/terminal_slides/run.rb
25
+ - lib/terminal_slides/slide_loader.rb
26
+ - lib/terminal_slides/slide_reader.rb
27
+ homepage:
28
+ licenses: []
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubygems_version: 3.0.6
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Simple presentations in terminal
49
+ test_files: []