pipetext 0.2.8 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba53fc33438b2a42562a17da2505e8da554cd98f5d368036a78e2c90e71f8ad7
4
- data.tar.gz: b982603d2a79f87c2f0d0a48e2bb60db73950d85137c5d19d98e0eb5504d8441
3
+ metadata.gz: 813ab78c2c3c8e17057651c1f751279a5308cb4777f955dc4b9bb7146f1ff2da
4
+ data.tar.gz: 2c7bb27bc71c0f8817c7477d3999d1ec029421062e51b24634fdc97e1eb7b178
5
5
  SHA512:
6
- metadata.gz: 3674e697f5b8752e9c18d084cd842a7f993250d3b4c2a88793b068db87a7ae36bbe3d0d835da6861e1b79b53560b49bfaa8ceba8c02faf02eac770ae20da7082
7
- data.tar.gz: 0a81c29b126508d23c687af4364af8c8c64ade4f5fbe89110b89f5dffef044051bec007da56502b2ad5b9ca5045747e7e35bd67e04a986bfa84d98675d8a0c70
6
+ metadata.gz: 67dca18b2cb23afbd2aad1087348d7099d2eb6be02b271456c9292535e18743f6b7610a9fc658588e06a021c6c4abe8fdcddd277546c6c18d6ec3465dd5e762a
7
+ data.tar.gz: 7e759796cd57567ebb4a3746bddd2a4a64f071a3537d7de09bbcfde5172fde20fe502956c67086650ba238dd33963c045f81a97fbf30608482db2b41013c91bb
@@ -51,40 +51,29 @@ module PipeText
51
51
  "remap" => Hash.new, # Used to remap pipetext codes
52
52
  "shell_prompt" => false # Used to add \[ and \] around non-printables for prompts
53
53
  }
54
- # attributes["variables"]["height"] = `tput lines`.chomp
55
- # attributes["variables"]["width"] = `tput cols`.chomp
56
54
  attributes["variables"]["height"], attributes["variables"]["width"] = IO.console.winsize
57
55
  return attributes
58
56
  end
59
57
 
60
58
  def pipe(text, attributes)
61
59
  new_text = String.new
62
- #puts "start pos = #{attributes["position"]}"
63
60
  if(text != "")
64
- #puts "text = #{text.inspect}"
65
61
  if(attributes["remap"] != {})
66
- #puts "remap before = #{text.inspect}"
67
62
  attributes["remap"].each do |old, new|
68
63
  text.gsub!(old, new)
69
64
  end
70
- #puts "remap after = #{text.inspect}"
71
65
  end
72
66
  attributes["remap"] = Hash.new
73
-
74
67
  text.chars.each do |character|
75
68
  process_character(character, new_text, attributes)
76
69
  if(new_text =~ /.*\n(.*)$/m)
77
70
  attributes["position"] = printable_length($1)
78
71
  else
79
- # attributes["position"] += printable_length(character)
80
- # attributes["position"] += printable_length(new_text)
81
72
  attributes["position"] = printable_length(new_text)
82
73
  end
83
- #puts "pos = #{attributes["position"]}"
84
74
  end
85
75
  end
86
- #puts "end pos = #{attributes["position"]}"
87
- # Clean up in case we"ve captured something we didn"t process yet
76
+ # Clean up in case we've captured something we didn't process yet
88
77
  if(attributes["color_capture"] > 0)
89
78
  emit_color(new_text, attributes)
90
79
  elsif(attributes["palette_capture"] > 0)
@@ -122,7 +111,7 @@ module PipeText
122
111
  new_text = String.new
123
112
  end
124
113
  end
125
- # Clean up in case we"ve captured something we didn"t process yet
114
+ # Clean up in case we've captured something we didn't process yet
126
115
  if(attributes["color_capture"] > 0)
127
116
  emit_color(new_text, attributes)
128
117
  elsif(attributes["palette_capture"] > 0)
@@ -296,11 +285,9 @@ module PipeText
296
285
  ord == 126980 ||
297
286
  ord == 127183 ||
298
287
  ord == 127374 ||
299
- ord == 127377 ||
300
- ord == 127378 ||
288
+ ord == 127377 || ord == 127378 ||
301
289
  ord == 127379 ||
302
- ord == 127381 ||
303
- ord == 127382 ||
290
+ ord == 127381 || ord == 127382 ||
304
291
  ord == 127383 ||
305
292
  (ord >= 127462 && ord <= 127487) ||
306
293
  (ord >= 127744 && ord <= 129791) ||
@@ -313,8 +300,6 @@ module PipeText
313
300
  (ord >= 196608 && ord <= 201546) ||
314
301
  (ord >= 201552 && ord <= 262143))
315
302
  return true
316
- # elsif(character[1] != nil)
317
- # return true
318
303
  end
319
304
  return false
320
305
  end
@@ -331,9 +316,7 @@ module PipeText
331
316
  zero_width_join = false
332
317
  last_was_wide = false
333
318
  country_code = false
334
- #puts "string = #{string.inspect}"
335
319
  string.chars.each do |character|
336
- #puts "char = #{character.inspect} - #{character[0].ord}"
337
320
  if(character[0].ord == 27)
338
321
  escape = true
339
322
  elsif(character[0].ord == 226 && wide == false)
@@ -387,11 +370,10 @@ module PipeText
387
370
  if(wide == true && wide_count > 0)
388
371
  length += 1
389
372
  end
390
- #puts "length = #{length}"
391
373
  return length
392
374
  end
393
375
 
394
- def with_spinner(spinner="⠇⠏⠋⠙⠹⠸⣰⣠⣄⣆", colors=["|r", "|g", "|b", "|m"])
376
+ def with_spinner(spinner="⠇⠏⠋⠙⠹⠸⣰⣠⣄⣆", colors=["|n"])
395
377
  spinner_thread = Thread.new do
396
378
  count = 0
397
379
  if(colors == nil)
@@ -421,6 +403,29 @@ module PipeText
421
403
  end
422
404
  end
423
405
 
406
+ def with_spinner_mode(mode=0, &block)
407
+ if(mode == 0)
408
+ with_spinner(&block)
409
+ elsif(mode == 1)
410
+ with_spinner(["🌑", "🌒", "🌓", "🌔", "🌕", "🌖", "🌗", "🌘",
411
+ "🌑", "🌘", "🌗", "🌖", "🌕", "🌔", "🌓", "🌒"], &block)
412
+ elsif(mode == 2)
413
+ with_spinner(["🕐", "🕑", "🕒", "🕓", "🕔", "🕕", "🕖", "🕗", "🕘", "🕙", "🕚", "🕛"], &block)
414
+ elsif(mode == 3)
415
+ with_spinner(["◐", "◓", "◑", "◒"], &block)
416
+ elsif(mode == 4)
417
+ with_spinner(["◜", "◠", "◝", "◞", "◡", "◟"], &block)
418
+ elsif(mode == 5)
419
+ with_spinner(["⠁", "⠂", "⠄", "⠂"], &block)
420
+ elsif(mode == 6)
421
+ with_spinner([" ", "▃", "▄", "▅", "▆", "▇", "█", "▇", "▆", "▅", "▄", "▃"], &block)
422
+ elsif(mode == 7)
423
+ with_spinner(["◰", "◳", "◲", "◱"], &block)
424
+ elsif(mode == 8)
425
+ with_spinner(["🔴", "🟠", "🟡", "🟢", "🔵", "🟣"], &block)
426
+ end
427
+ end
428
+
424
429
  private
425
430
 
426
431
  def process_character(character, new_text, attributes)
@@ -759,8 +764,6 @@ module PipeText
759
764
  end
760
765
  if(spaces > 0)
761
766
  spaces /= 2
762
- #puts "center | start = #{attributes["position"]}, end = #{attributes["end"]}"
763
- #puts "center | text = #{text.inspect}, length = #{length}, spaces = #{spaces}"
764
767
  spaces.times do
765
768
  new_text << " "
766
769
  end
@@ -773,9 +776,7 @@ module PipeText
773
776
  def emit_right(new_text, attributes)
774
777
  text = pipetext(attributes["right"], attributes["box_mode"], attributes["ampersand_mode"])
775
778
  length = printable_length(text)
776
- #puts "right | start = #{attributes["position"]}, end = #{attributes["end"]}"
777
779
  spaces = attributes["end"] - attributes["position"] - length
778
- #puts "right | text = #{text.inspect}, length = #{length}, spaces = #{spaces}"
779
780
  if(spaces > 0)
780
781
  spaces.times do
781
782
  new_text << " "
@@ -1064,26 +1065,18 @@ module PipeText
1064
1065
  end
1065
1066
 
1066
1067
  def max_line_length(line, max)
1067
- #puts "mll = #{line.inspect}, #{max.inspect}"
1068
1068
  if(line =~ /^(.*)\|\\n(.*)$/m || line =~ /^([^\n]*)\n(.*)$/m)
1069
1069
  if($1 != nil)
1070
- #puts "$1 = #{$1.inspect}"
1071
1070
  length = printable_length($1)
1072
- #puts "len 1 = #{length}"
1073
1071
  if(length > max)
1074
1072
  max = length
1075
- #puts "max 1 = #{max}"
1076
1073
  end
1077
1074
  end
1078
- #puts "$2 = #{$2.inspect}"
1079
1075
  return max_line_length($2, max)
1080
1076
  elsif(line != nil)
1081
1077
  length = printable_length(line)
1082
- #puts "line = #{line.inspect}"
1083
- #puts "len 2 = #{length}"
1084
1078
  if(length > max)
1085
1079
  max = length
1086
- #puts "max 2 = #{max}"
1087
1080
  end
1088
1081
  end
1089
1082
  return max
@@ -1282,7 +1275,6 @@ module PipeText
1282
1275
  else
1283
1276
  box["clip_children"] = false
1284
1277
  end
1285
- #puts box.inspect
1286
1278
  end
1287
1279
  end
1288
1280
 
@@ -1334,7 +1326,6 @@ module PipeText
1334
1326
  join = false
1335
1327
  else
1336
1328
  box_set(text_x, text_y, collect + character, bg_color, fg_color)
1337
- # box_set(text_x, text_y, character, bg_color, fg_color + collect)
1338
1329
  collect = String.new
1339
1330
  text_x += 1
1340
1331
  end
@@ -1392,7 +1383,6 @@ module PipeText
1392
1383
  end
1393
1384
 
1394
1385
  def draw_box_frame(box, x, y, width, height)
1395
- #puts "dbf y = #{y} x = #{x}, height = #{height}, width = #{width}"
1396
1386
  title_height = 0
1397
1387
  box_symbol = Hash.new
1398
1388
  wide_border = false
@@ -1406,8 +1396,6 @@ module PipeText
1406
1396
  end
1407
1397
  x_offset += box["outside_border"]
1408
1398
  y_offset += box["outside_border"]
1409
- #puts "x_off0 = #{x_offset}"
1410
- #puts "y_off0 = #{y_offset}"
1411
1399
  if(box["title"] != "")
1412
1400
  text_y = y + y_offset + 1
1413
1401
  text_x = x + x_offset + 1
@@ -1428,11 +1416,7 @@ module PipeText
1428
1416
  new_attributes["end"] -= (2 * x_offset)
1429
1417
  if(new_attributes["end"] > 0)
1430
1418
  new_attributes["position"] = 0
1431
- #puts "title | start = #{new_attributes["position"]}, end = #{new_attributes["end"]}"
1432
- #puts "title | text = #{box["title"].inspect}"
1433
1419
  box["title"] = pipe(box["title"], new_attributes)
1434
- #puts "title | attrib = #{new_attributes.inspect}"
1435
- #puts "title | pipe = #{box["title"].inspect}"
1436
1420
  if(text_y < y + height && box["title"] != "")
1437
1421
  box["title"].lines.each do |line|
1438
1422
  if(text_y < y + height)
@@ -1514,17 +1498,8 @@ module PipeText
1514
1498
  else
1515
1499
  x_offset += 1
1516
1500
  end
1517
- #puts "x_off1 = #{x_offset}"
1518
1501
  y_offset += title_height
1519
1502
  y += title_height + 1
1520
-
1521
- #@drawing.each do |location, data|
1522
- # if(data["symbol"] != " ")
1523
- #puts "#{location.inspect} = #{data.inspect}"
1524
- # end
1525
- #end
1526
-
1527
- #puts "y_off1 = #{y_offset}, y = #{y}"
1528
1503
  return y, wide_border, x_offset, y_offset
1529
1504
  end
1530
1505
 
@@ -1555,7 +1530,6 @@ module PipeText
1555
1530
  # box_set(column, row, " ", box["inside_border_background_color"], box["foreground_color"])
1556
1531
  # end
1557
1532
  # end
1558
-
1559
1533
  if(row < y + y_offset + border_size || row >= y + height - y_offset - border_size - 2 ||
1560
1534
  column < x + x_offset + border_size || column > x + width - x_offset - border_size - 1)
1561
1535
  box_set(column, row, " ", box["inside_border_background_color"], box["foreground_color"])
@@ -1578,14 +1552,11 @@ module PipeText
1578
1552
  def draw_box_text(box, x, y, width, height, x_offset, y_offset)
1579
1553
  text_x = x + x_offset
1580
1554
  text_y = y + y_offset
1581
- #puts "draw | text_x = #{text_x} | x = #{x} off = #{x_offset}, width = #{width}"
1582
1555
  new_attributes = pipetext_init
1583
1556
  new_attributes["remap"] = { "|n" => box["fg_pipe_color"], "&n" => box["bg_pipe_color"] }
1584
1557
  new_attributes["ampersand_mode"] = true
1585
1558
  new_attributes["end"] = width
1586
1559
  new_attributes["position"] = 0
1587
- #puts "draw | start = #{new_attributes["position"]}, end = #{new_attributes["end"]}"
1588
- #puts "draw | text = #{box["capture"].inspect}"
1589
1560
  box["capture"] = pipe(box["capture"], new_attributes)
1590
1561
  if(text_y < y + height && box["capture"] != "")
1591
1562
  box["capture"].lines.each do |line|
@@ -1605,22 +1576,13 @@ module PipeText
1605
1576
  inside_height = height - (y_offset * 2)
1606
1577
  current_x = inside_x
1607
1578
  current_y = inside_y
1608
-
1609
- #puts "child | x = #{x}, x_offset = #{x_offset}, width = #{width}"
1610
- #puts "child | y = #{y}, y_offset = #{y_offset}, height = #{height}"
1611
- #puts "child | inside_x = #{inside_x}, inside_width = #{inside_width}, current_x = #{current_x}"
1612
- #puts "child | inside_y = #{inside_y}, inside_height = #{inside_height}, current_y = #{current_y}"
1613
-
1614
1579
  attributes["box_attributes"].each do |index, inside_box|
1615
1580
  if(inside_box["parent"] == box_index)
1616
1581
  inside_width = inside_box["width"]
1617
1582
  inside_height = inside_box["height"]
1618
- #puts "start | inside_height = #{inside_height}, inside_width = #{inside_width}"
1619
1583
  if(box["layout"] == "horizontal")
1620
- #puts "horizontal"
1621
1584
  available_width = width - x_offset - current_x
1622
1585
  available_height = height - current_y - 1
1623
- #puts "child2 | available_width = #{available_width}, available_height = #{available_height}"
1624
1586
  if(inside_box["grow"] == true)
1625
1587
  inside_width = available_width
1626
1588
  inside_height = available_height
@@ -1630,13 +1592,10 @@ module PipeText
1630
1592
  inside_height = [inside_height, available_height].min
1631
1593
  end
1632
1594
  if(inside_width > 2 && inside_height > 2)
1633
- #puts "child2 | inside_x = #{inside_x}, inside_width = #{inside_width}, current_x = #{current_x}"
1634
- #puts "child2 | inside_y = #{inside_y}, inside_height = #{inside_height}, current_y = #{current_y}"
1635
1595
  box_draw(attributes, index, current_x, current_y, inside_width, inside_height)
1636
1596
  current_x += inside_width
1637
1597
  end
1638
1598
  else
1639
- #puts "vertical"
1640
1599
  available_width = (x + width - x_offset) - current_x
1641
1600
  available_height = (y + height - (2 * y_offset)) - current_y - 1
1642
1601
  if(inside_box["grow"] == true)
@@ -1676,12 +1635,10 @@ module PipeText
1676
1635
  draw_box_background(box, x, y, height, width)
1677
1636
  if(box["border_mode"] >= 0)
1678
1637
  y, wide_frame_border, x_offset, y_offset = draw_box_frame(box, x, y, width, height)
1679
- #puts "x_off2 = #{x_offset}"
1680
1638
  end
1681
1639
  draw_box_inside_border(box, x, y, width, height, x_offset, y_offset, wide_frame_border)
1682
1640
  x_offset += box["inside_border"]
1683
1641
  y_offset += box["inside_border"]
1684
- #puts "y_off2 = #{y_offset}, y = #{y}"
1685
1642
  text_width = width - (2 * box["outside_border"])
1686
1643
  text_height = height - (2 * box["outside_border"])
1687
1644
  if(box["border_mode"] >= 0)
@@ -1694,7 +1651,6 @@ module PipeText
1694
1651
  text_width -= (2 * box["inside_border"])
1695
1652
  text_height -= (2 * box["inside_border"])
1696
1653
  y = draw_box_text(box, x, y, text_width, text_height, x_offset, y_offset)
1697
- #puts "y_off3 = #{y_offset}, y = #{y}"
1698
1654
  draw_box_children(attributes, box_index, x, y, width, height, x_offset, y_offset)
1699
1655
  end
1700
1656
 
@@ -1721,7 +1677,6 @@ module PipeText
1721
1677
  wide -= 1
1722
1678
  else
1723
1679
  if(double_wide_character(location["symbol"]))
1724
- #puts "dw = #{location["symbol"].inspect}"
1725
1680
  wide += 1
1726
1681
  end
1727
1682
  bg = String.new
@@ -1745,7 +1700,6 @@ module PipeText
1745
1700
  previous_bg = bg
1746
1701
  end
1747
1702
  end
1748
- #puts "row = #{row.inspect}"
1749
1703
  rendered_box << row.join
1750
1704
  end
1751
1705
  rendered_box.each do |line|
@@ -1920,15 +1874,6 @@ module PipeText
1920
1874
  end
1921
1875
 
1922
1876
  def process_piped_character(character, new_text, attributes)
1923
- if(attributes["remap"]["|#{character}"] != nil)
1924
- # character = attributes["remap"]["|#{character}"].sub(/^\|/, "")
1925
- attributes["remap"]["|#{character}"].sub(/^\|/, "").chars.each do |c|
1926
- process_character(c, new_text, attributes)
1927
- end
1928
- puts "| remapped = |#{character.inspect}"
1929
- puts new_text.inspect
1930
- return
1931
- end
1932
1877
  attributes["found"] = true # Assume we will find the next character
1933
1878
  if(attributes["num"] == 0) # We are not in repeat character mode
1934
1879
  case character
@@ -2123,8 +2068,6 @@ puts new_text.inspect
2123
2068
  end
2124
2069
  when "]" # |]0-9* - end column number
2125
2070
  attributes["end_capture"] = true
2126
- # this makes bugs, what does it solve?
2127
- # attributes["position"] = 0 # Reset position
2128
2071
  when "[" # |[emoji]
2129
2072
  attributes["emoji_capture"] = true
2130
2073
  when "(" # |(variable) or |(variable=Some value)
@@ -2186,14 +2129,6 @@ puts new_text.inspect
2186
2129
  end
2187
2130
 
2188
2131
  def process_ampersanded_character(character, new_text, attributes)
2189
- if(attributes["remap"]["&#{character}"] != nil)
2190
- # character = attributes["remap"]["&#{character}"].sub(/^&/, "")
2191
- attributes["remap"]["|#{character}"].sub(/^\&/, "").chars.each do |c|
2192
- process_character(c, new_text, attributes)
2193
- end
2194
- puts "& remapped = &#{character.inspect}"
2195
- return
2196
- end
2197
2132
  case character
2198
2133
  when "#" # &#RRGGBB
2199
2134
  attributes["color_capture"] = 1
File without changes
@@ -2,6 +2,6 @@ module PipeText
2
2
 
3
3
  public
4
4
 
5
- VERSION = "0.2.8"
5
+ VERSION = "0.2.9"
6
6
  end
7
7
 
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pipetext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minaswan Nakamoto