monty-ai 0.3.0 → 0.4.0

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: 3629f5464a5385a0172fc0cdc9b8408e4ec1d226d3d92f5ca84bfc95797cc8b1
4
- data.tar.gz: 8060d8acb3c53732a706c39fdf543623da08c1084ede939ca2e5934cb2b281b4
3
+ metadata.gz: 81eee1ee0bb2c708fbac144ed4c897ef4fca4bfcf92092788cab32eae197a48b
4
+ data.tar.gz: 64867682c15ff89c95cbbbe59c2a629fb45d39172981121ed731b2acc1467beb
5
5
  SHA512:
6
- metadata.gz: bfa2e790a74682e261728403dec11885ec56bb9ec46c24e94ab0b8abb2046f526ca5040a79c8654f1df7f763bf7ca352a7da9e8b6c7e8795c12986eae8a3b750
7
- data.tar.gz: 6acb0bac8b787f82304f4aae5f2cb17c8766c62d5cd673aa07685315cd7741a918908008d8a8aee81f782b5004361c37f8b23e4d175ac46714b69e7186f9462b
6
+ metadata.gz: 92ffc6b0b9f2d6836539e165e97f16d085ea57449b349b391217a8c301f724ab748cf4d7c25ecf99be5f3306904edb9cf027100bc199079da16ac7df23c7b1ab
7
+ data.tar.gz: c9ec6226aa8d9d316c5a1e88bd2d42a4be2d4bb2c4f69617e7683fb6ac15d4ea44cc8e08e5787e7331fe2b06fa5705de5e364096c27f8d7a8c741f7bdec36ed1
data/Gemfile.lock CHANGED
@@ -2,6 +2,8 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  monty-ai (0.3.0)
5
+ pastel (~> 0.8.0)
6
+ rouge (~> 4.0)
5
7
  thor (~> 1.2)
6
8
 
7
9
  GEM
@@ -22,6 +24,8 @@ GEM
22
24
  parser (3.3.7.4)
23
25
  ast (~> 2.4.1)
24
26
  racc
27
+ pastel (0.8.0)
28
+ tty-color (~> 0.5)
25
29
  pp (0.6.2)
26
30
  prettyprint
27
31
  prettyprint (0.2.0)
@@ -37,6 +41,7 @@ GEM
37
41
  regexp_parser (2.10.0)
38
42
  reline (0.6.1)
39
43
  io-console (~> 0.5)
44
+ rouge (4.5.1)
40
45
  rspec (3.13.0)
41
46
  rspec-core (~> 3.13.0)
42
47
  rspec-expectations (~> 3.13.0)
@@ -83,6 +88,7 @@ GEM
83
88
  rubocop-performance (~> 1.25.0)
84
89
  stringio (3.1.6)
85
90
  thor (1.3.2)
91
+ tty-color (0.6.0)
86
92
  unicode-display_width (3.1.4)
87
93
  unicode-emoji (~> 4.0, >= 4.0.4)
88
94
  unicode-emoji (4.0.4)
data/lib/monty_ai/cli.rb CHANGED
@@ -28,6 +28,8 @@ module MontyAI
28
28
 
29
29
  private
30
30
 
31
+ # lib/monty_ai/cli.rb
32
+ # In the handle_code method:
31
33
  def handle_code(code, filename = nil)
32
34
  puts "Analyzing code..."
33
35
 
@@ -40,7 +42,7 @@ module MontyAI
40
42
  puts ""
41
43
  end
42
44
 
43
- puts Formatter.format(explanation)
45
+ puts Formatter.format(explanation, code, filename)
44
46
  rescue Error => e
45
47
  puts "Error: #{e.message}"
46
48
  exit 1
@@ -1,11 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # lib/monty_ai/formatter.rb
3
4
  module MontyAI
4
5
  class Formatter
5
- def self.format(explanation)
6
- # Simple formatter that just returns the explanation
7
- # In future versions, this could be enhanced to do more formatting
8
- explanation
6
+ def self.format(explanation, code = nil, filename = nil)
7
+ # If no code is provided, just return the explanation
8
+ return explanation unless code
9
+
10
+ # Initialize highlighter
11
+ highlighter = SyntaxHighlighter.new
12
+ language = filename ? highlighter.detect_language(filename) : :text
13
+
14
+ # Highlight the code
15
+ highlighted_code = highlighter.highlight(code, language)
16
+
17
+ # Format the output with highlighted code
18
+ output = []
19
+ output << "```"
20
+ output << highlighted_code
21
+ output << "```"
22
+ output << ""
23
+ output << "Explanation:"
24
+ output << explanation
25
+
26
+ output.join("\n")
9
27
  end
10
28
  end
11
29
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rouge"
4
+ require "pastel"
5
+
6
+ module MontyAI
7
+ class SyntaxHighlighter
8
+ def initialize
9
+ @pastel = Pastel.new
10
+ end
11
+
12
+ def highlight(code, language = :ruby)
13
+ formatter = Rouge::Formatters::Terminal256.new(Rouge::Themes::Monokai.new)
14
+ lexer = Rouge::Lexer.find(language.to_s) || Rouge::Lexers::PlainText.new
15
+ formatter.format(lexer.lex(code))
16
+ end
17
+
18
+ def detect_language(filename)
19
+ extension = File.extname(filename).downcase
20
+
21
+ case extension
22
+ when ".go"
23
+ :go
24
+ when ".rb"
25
+ :ruby
26
+ when ".js"
27
+ :javascript
28
+ when ".jsx"
29
+ :react_javascript
30
+ when ".py"
31
+ :python
32
+ when ".java"
33
+ :java
34
+ when ".php"
35
+ :php
36
+ when ".rs"
37
+ :rust
38
+ when ".ts"
39
+ :typescript
40
+ when ".tsx"
41
+ :react_typescript
42
+ else
43
+ :text
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MontyAI
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/monty_ai.rb CHANGED
@@ -4,6 +4,7 @@ require "monty_ai/version"
4
4
  require "monty_ai/cli"
5
5
  require "monty_ai/ai_client"
6
6
  require "monty_ai/file_handler"
7
+ require "monty_ai/syntax_highlighter"
7
8
  require "monty_ai/formatter"
8
9
 
9
10
  # @!parse
data/monty_ai.gemspec CHANGED
@@ -27,6 +27,8 @@ Gem::Specification.new do |spec|
27
27
  spec.require_paths = ["lib"]
28
28
 
29
29
  # Dependencies
30
+ spec.add_dependency "pastel", "~> 0.8.0" # For terminal colors
31
+ spec.add_dependency "rouge", "~> 4.0" # For syntax highlighting
30
32
  spec.add_dependency "thor", "~> 1.2"
31
33
 
32
34
  # Development dependencies
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monty-ai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Cook
@@ -9,6 +9,34 @@ bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: pastel
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: 0.8.0
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: 0.8.0
26
+ - !ruby/object:Gem::Dependency
27
+ name: rouge
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '4.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '4.0'
12
40
  - !ruby/object:Gem::Dependency
13
41
  name: thor
14
42
  requirement: !ruby/object:Gem::Requirement
@@ -109,6 +137,7 @@ files:
109
137
  - lib/monty_ai/cli.rb
110
138
  - lib/monty_ai/file_handler.rb
111
139
  - lib/monty_ai/formatter.rb
140
+ - lib/monty_ai/syntax_highlighter.rb
112
141
  - lib/monty_ai/version.rb
113
142
  - monty_ai.gemspec
114
143
  - montyai-logo.svg