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 +4 -4
- data/lib/beniya/application.rb +4 -1
- data/lib/beniya/file_preview.rb +11 -3
- data/lib/beniya/keybind_handler.rb +211 -671
- data/lib/beniya/terminal_ui.rb +54 -25
- data/lib/beniya/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eabacf1e9c20898106af324c8275d857b209150badec6518d211a1820a78778f
|
4
|
+
data.tar.gz: 4e43ee255191fdad616db68a320d77f326e7fb925932145cdf6e528a4f6f67ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19f7fba9a329ca1dae8b3fa1d63898af7e0f16030bbf60cb8e8b10d5af02d4e2bbba783fef30df30e2c212fef06bb07628b9122139d0c50a093752f4a2bdb0a0
|
7
|
+
data.tar.gz: d3a21a8322852750a2410145ffbd63d4c0ed72c7ae5485b6763f68d192872f05a4b7ddea62900ca910c21e04252347bcbcd679b2c1b5fbbe7721734fea8db2d8
|
data/lib/beniya/application.rb
CHANGED
@@ -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(
|
28
|
+
puts e.backtrace.first(BACKTRACE_LINES).join("\n")
|
26
29
|
end
|
27
30
|
end
|
28
31
|
end
|
data/lib/beniya/file_preview.rb
CHANGED
@@ -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,
|
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
|
-
|
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
|
|