beniya 0.6.0 → 0.6.1

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: 8e920583f6645634b10889369089e81e114db44a01be5b0baa177dc8279ca1bc
4
- data.tar.gz: 7c3ec6afa823e45700e26fa02c50076cbdc268d136d11403599a6befc858aebf
3
+ metadata.gz: eabacf1e9c20898106af324c8275d857b209150badec6518d211a1820a78778f
4
+ data.tar.gz: 4e43ee255191fdad616db68a320d77f326e7fb925932145cdf6e528a4f6f67ef
5
5
  SHA512:
6
- metadata.gz: bd20c3f4392c8d65aec9bc2e3261701d5f091e6baa73012e779f7417e0d2ea1bc8fe10ea4cac99117b70f82a70b68de0638ec05b390e97436c67691ac11bef90
7
- data.tar.gz: b28475770533a0d8989eab47f72bf63a83e15546fa4e11a43027e45885c07b491498c0bd83296fe9e67a4568c3c1774f96b8b6ff9bd98d1ea6f2b9d185d4ea30
6
+ metadata.gz: 19f7fba9a329ca1dae8b3fa1d63898af7e0f16030bbf60cb8e8b10d5af02d4e2bbba783fef30df30e2c212fef06bb07628b9122139d0c50a093752f4a2bdb0a0
7
+ data.tar.gz: d3a21a8322852750a2410145ffbd63d4c0ed72c7ae5485b6763f68d192872f05a4b7ddea62900ca910c21e04252347bcbcd679b2c1b5fbbe7721734fea8db2d8
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Beniya
4
4
  class Application
5
+ # Error display constants
6
+ BACKTRACE_LINES = 5 # Number of backtrace lines to show
7
+
5
8
  def initialize(start_directory = Dir.pwd)
6
9
  @start_directory = File.expand_path(start_directory)
7
10
  # Load configuration including language settings
@@ -22,7 +25,7 @@ module Beniya
22
25
  puts "\n\n#{ConfigLoader.message('app.interrupted')}"
23
26
  rescue StandardError => e
24
27
  puts "\n#{ConfigLoader.message('app.error_occurred')}: #{e.message}"
25
- puts e.backtrace.first(5).join("\n")
28
+ puts e.backtrace.first(BACKTRACE_LINES).join("\n")
26
29
  end
27
30
  end
28
31
  end
@@ -6,6 +6,13 @@ module Beniya
6
6
  DEFAULT_MAX_LINES = 50
7
7
  MAX_LINE_LENGTH = 500
8
8
 
9
+ # Binary detection constants
10
+ BINARY_SAMPLE_SIZE = 512
11
+ PRINTABLE_CHAR_THRESHOLD = 32
12
+ CONTROL_CHAR_TAB = 9
13
+ CONTROL_CHAR_NEWLINE = 10
14
+ CONTROL_CHAR_CARRIAGE_RETURN = 13
15
+
9
16
  def initialize
10
17
  # future: hold syntax highlight settings etc.
11
18
  end
@@ -19,7 +26,7 @@ module Beniya
19
26
 
20
27
  begin
21
28
  # binary file detection
22
- sample = File.binread(file_path, [file_size, 512].min)
29
+ sample = File.binread(file_path, [file_size, BINARY_SAMPLE_SIZE].min)
23
30
  return binary_response(file_path) if binary_file?(sample)
24
31
 
25
32
  # process as text file
@@ -44,8 +51,9 @@ module Beniya
44
51
 
45
52
  def binary_file?(sample)
46
53
  return false if sample.empty?
47
-
48
- binary_chars = sample.bytes.count { |byte| byte < 32 && ![9, 10, 13].include?(byte) }
54
+
55
+ allowed_control_chars = [CONTROL_CHAR_TAB, CONTROL_CHAR_NEWLINE, CONTROL_CHAR_CARRIAGE_RETURN]
56
+ binary_chars = sample.bytes.count { |byte| byte < PRINTABLE_CHAR_THRESHOLD && !allowed_control_chars.include?(byte) }
49
57
  (binary_chars.to_f / sample.bytes.length) > BINARY_THRESHOLD
50
58
  end
51
59