✨ initial commit
15
sample/basic_example.svg
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<svg width="506.67" height="201.00" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="506.67" height="201.00" fill="#ffffff" x="0.00px" y="0.00px"/>
|
||||
<g font-family="JetBrains Mono" font-size="14.00px" fill="#-00001" clip-path="url(#terminalMask)">
|
||||
<text x="20.00px" y="36.80px" xml:space="preserve"><tspan fill="#cf222e">package</tspan> <tspan fill="#1f2328">main</tspan>
|
||||
</text><text x="20.00px" y="53.60px" xml:space="preserve">
|
||||
</text><text x="20.00px" y="70.40px" xml:space="preserve"><tspan fill="#cf222e">import</tspan> <tspan fill="#0a3069">"fmt"</tspan>
|
||||
</text><text x="20.00px" y="87.20px" xml:space="preserve">
|
||||
</text><text x="20.00px" y="104.00px" xml:space="preserve"><tspan fill="#cf222e">func</tspan> <tspan fill="#6639ba">main</tspan><tspan fill="#1f2328">()</tspan> <tspan fill="#1f2328">{</tspan>
|
||||
</text><text x="20.00px" y="120.80px" xml:space="preserve"> <tspan fill="#1f2328">fmt</tspan><tspan fill="#1f2328">.</tspan><tspan fill="#6639ba">Println</tspan><tspan fill="#1f2328">(</tspan><tspan fill="#0a3069">"Hello, World!"</tspan><tspan fill="#1f2328">)</tspan>
|
||||
</text><text x="20.00px" y="137.60px" xml:space="preserve"> <tspan fill="#1f2328">fmt</tspan><tspan fill="#1f2328">.</tspan><tspan fill="#6639ba">Println</tspan><tspan fill="#1f2328">(</tspan><tspan fill="#0a3069">"This is a beautiful code screenshot!"</tspan><tspan fill="#1f2328">)</tspan>
|
||||
</text><text x="20.00px" y="154.40px" xml:space="preserve"><tspan fill="#1f2328">}</tspan></text>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.6 KiB |
24
sample/chained_example.svg
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<svg width="553.57" height="414.29" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="521.57" height="382.29" fill="#272822" rx="10.00" ry="10.00" filter="url(#shadow)" stroke="#444444" stroke-width="1.00" x="15.00px" y="15.00px"/>
|
||||
<g font-family="Cascadia Code" font-size="15.00px" fill="#f8f8f2" clip-path="url(#terminalMask)">
|
||||
<text x="40.00px" y="73.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 1 </tspan><tspan fill="#75715e">#include</tspan> <tspan fill="#75715e"><iostream></tspan><tspan fill="#75715e">
|
||||
</tspan></text><text x="40.00px" y="91.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 2 </tspan><tspan fill="#75715e">#include</tspan> <tspan fill="#75715e"><vector></tspan><tspan fill="#75715e">
|
||||
</tspan></text><text x="40.00px" y="109.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 3 </tspan><tspan fill="#75715e">#include</tspan> <tspan fill="#75715e"><algorithm></tspan><tspan fill="#75715e">
|
||||
</tspan></text><text x="40.00px" y="127.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 4 </tspan><tspan fill="#75715e"/>
|
||||
</text><text x="40.00px" y="145.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 5 </tspan><tspan fill="#66d9ef">int</tspan> <tspan fill="#a6e22e">main</tspan>() {
|
||||
</text><text x="40.00px" y="163.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 6 </tspan> std<tspan fill="#f92672">::</tspan>vector<tspan fill="#f92672"><</tspan><tspan fill="#66d9ef">int</tspan><tspan fill="#f92672">></tspan> numbers <tspan fill="#f92672">=</tspan> {<tspan fill="#ae81ff">5</tspan>, <tspan fill="#ae81ff">2</tspan>, <tspan fill="#ae81ff">8</tspan>, <tspan fill="#ae81ff">1</tspan>, <tspan fill="#ae81ff">9</tspan>};
|
||||
</text><text x="40.00px" y="181.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 7 </tspan>
|
||||
</text><text x="40.00px" y="199.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 8 </tspan> std<tspan fill="#f92672">::</tspan>sort(numbers.begin(), numbers.end());
|
||||
</text><text x="40.00px" y="217.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 9 </tspan>
|
||||
</text><text x="40.00px" y="235.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 10 </tspan> std<tspan fill="#f92672">::</tspan>cout <tspan fill="#f92672"><<</tspan> <tspan fill="#e6db74">"Sorted numbers: "</tspan>;
|
||||
</text><text x="40.00px" y="253.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 11 </tspan> <tspan fill="#66d9ef">for</tspan> (<tspan fill="#66d9ef">const</tspan> <tspan fill="#66d9ef">auto</tspan><tspan fill="#f92672">&</tspan> num : numbers) {
|
||||
</text><text x="40.00px" y="271.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 12 </tspan> std<tspan fill="#f92672">::</tspan>cout <tspan fill="#f92672"><<</tspan> num <tspan fill="#f92672"><<</tspan> <tspan fill="#e6db74">" "</tspan>;
|
||||
</text><text x="40.00px" y="289.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 13 </tspan> }
|
||||
</text><text x="40.00px" y="307.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 14 </tspan> std<tspan fill="#f92672">::</tspan>cout <tspan fill="#f92672"><<</tspan> std<tspan fill="#f92672">::</tspan>endl;
|
||||
</text><text x="40.00px" y="325.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 15 </tspan>
|
||||
</text><text x="40.00px" y="343.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 16 </tspan> <tspan fill="#66d9ef">return</tspan> <tspan fill="#ae81ff">0</tspan>;
|
||||
</text><text x="40.00px" y="361.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 17 </tspan>}</text>
|
||||
</g>
|
||||
<svg x="15.00px" y="15.00px"><circle cx="13.50" cy="12.00" r="5.50" fill="#FF5A54"/><circle cx="32.50" cy="12.00" r="5.50" fill="#E6BF29"/><circle cx="51.50" cy="12.00" r="5.50" fill="#52C12B"/></svg><defs><filter id="shadow" filterUnits="userSpaceOnUse"><feGaussianBlur in="SourceAlpha" stdDeviation="20.00"/><feOffset result="offsetblur" dx="0.00" dy="10.00"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge></filter></defs></svg>
|
After Width: | Height: | Size: 4.4 KiB |
25
sample/custom_config_example.svg
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<svg width="800.00" height="538.67" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="708.00" height="494.67" fill="#ffffff" rx="12.00" ry="12.00" filter="url(#shadow)" stroke="#d1d9e0" stroke-width="2.00" x="20.00px" y="20.00px"/>
|
||||
<g font-family="JetBrains Mono" font-size="16.00px" fill="#-00001" clip-path="url(#terminalMask)">
|
||||
<text x="50.00px" y="87.40px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 1 </tspan><tspan fill="#cf222e">import</tspan> <tspan fill="#24292e">numpy</tspan> <tspan fill="#cf222e">as</tspan> <tspan fill="#24292e">np</tspan>
|
||||
</text><text x="50.00px" y="109.80px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 2 </tspan><tspan fill="#cf222e">import</tspan> <tspan fill="#24292e">matplotlib.pyplot</tspan> <tspan fill="#cf222e">as</tspan> <tspan fill="#24292e">plt</tspan>
|
||||
</text><text x="50.00px" y="132.20px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 3 </tspan>
|
||||
</text><text x="50.00px" y="154.60px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 4 </tspan><tspan fill="#cf222e">def</tspan> <tspan fill="#6639ba">plot_sine_wave</tspan><tspan fill="#1f2328">():</tspan>
|
||||
</text><text x="50.00px" y="177.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 5 </tspan> x <tspan fill="#0550ae">=</tspan> np<tspan fill="#0550ae">.</tspan>linspace<tspan fill="#1f2328">(</tspan><tspan fill="#0550ae">0</tspan><tspan fill="#1f2328">,</tspan> <tspan fill="#0550ae">2</tspan> <tspan fill="#0550ae">*</tspan> np<tspan fill="#0550ae">.</tspan>pi<tspan fill="#1f2328">,</tspan> <tspan fill="#0550ae">100</tspan><tspan fill="#1f2328">)</tspan>
|
||||
</text><text x="50.00px" y="199.40px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 6 </tspan> y <tspan fill="#0550ae">=</tspan> np<tspan fill="#0550ae">.</tspan>sin<tspan fill="#1f2328">(</tspan>x<tspan fill="#1f2328">)</tspan>
|
||||
</text><text x="50.00px" y="221.80px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 7 </tspan>
|
||||
</text><text x="50.00px" y="244.20px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 8 </tspan> plt<tspan fill="#0550ae">.</tspan>figure<tspan fill="#1f2328">(</tspan>figsize<tspan fill="#0550ae">=</tspan><tspan fill="#1f2328">(</tspan><tspan fill="#0550ae">10</tspan><tspan fill="#1f2328">,</tspan> <tspan fill="#0550ae">6</tspan><tspan fill="#1f2328">))</tspan>
|
||||
</text><text x="50.00px" y="266.60px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 9 </tspan> plt<tspan fill="#0550ae">.</tspan>plot<tspan fill="#1f2328">(</tspan>x<tspan fill="#1f2328">,</tspan> y<tspan fill="#1f2328">,</tspan> <tspan fill="#0a3069">'b-'</tspan><tspan fill="#1f2328">,</tspan> linewidth<tspan fill="#0550ae">=</tspan><tspan fill="#0550ae">2</tspan><tspan fill="#1f2328">,</tspan> label<tspan fill="#0550ae">=</tspan><tspan fill="#0a3069">'sin(x)'</tspan><tspan fill="#1f2328">)</tspan>
|
||||
</text><text x="50.00px" y="289.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 10 </tspan> plt<tspan fill="#0550ae">.</tspan>xlabel<tspan fill="#1f2328">(</tspan><tspan fill="#0a3069">'x'</tspan><tspan fill="#1f2328">)</tspan>
|
||||
</text><text x="50.00px" y="311.40px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 11 </tspan> plt<tspan fill="#0550ae">.</tspan>ylabel<tspan fill="#1f2328">(</tspan><tspan fill="#0a3069">'sin(x)'</tspan><tspan fill="#1f2328">)</tspan>
|
||||
</text><text x="50.00px" y="333.80px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 12 </tspan> plt<tspan fill="#0550ae">.</tspan>title<tspan fill="#1f2328">(</tspan><tspan fill="#0a3069">'Sine Wave'</tspan><tspan fill="#1f2328">)</tspan>
|
||||
</text><text x="50.00px" y="356.20px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 13 </tspan> plt<tspan fill="#0550ae">.</tspan>grid<tspan fill="#1f2328">(</tspan><tspan fill="#cf222e">True</tspan><tspan fill="#1f2328">,</tspan> alpha<tspan fill="#0550ae">=</tspan><tspan fill="#0550ae">0.3</tspan><tspan fill="#1f2328">)</tspan>
|
||||
</text><text x="50.00px" y="378.60px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 14 </tspan> plt<tspan fill="#0550ae">.</tspan>legend<tspan fill="#1f2328">()</tspan>
|
||||
</text><text x="50.00px" y="401.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 15 </tspan> plt<tspan fill="#0550ae">.</tspan>show<tspan fill="#1f2328">()</tspan>
|
||||
</text><text x="50.00px" y="423.40px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 16 </tspan>
|
||||
</text><text x="50.00px" y="445.80px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 17 </tspan><tspan fill="#cf222e">if</tspan> <tspan fill="#953800">__name__</tspan> <tspan fill="#0550ae">==</tspan> <tspan fill="#0a3069">"__main__"</tspan><tspan fill="#1f2328">:</tspan>
|
||||
</text><text x="50.00px" y="468.20px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 18 </tspan> plot_sine_wave<tspan fill="#1f2328">()</tspan></text>
|
||||
</g>
|
||||
<svg x="20.00px" y="20.00px"><circle cx="13.50" cy="12.00" r="5.50" fill="#FF5A54"/><circle cx="32.50" cy="12.00" r="5.50" fill="#E6BF29"/><circle cx="51.50" cy="12.00" r="5.50" fill="#52C12B"/></svg><defs><filter id="shadow" filterUnits="userSpaceOnUse"><feGaussianBlur in="SourceAlpha" stdDeviation="25.00"/><feOffset result="offsetblur" dx="0.00" dy="15.00"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge></filter></defs><defs><clipPath id="terminalMask"><rect x="20.00" y="20.00" width="708.00" height="464.67"/></clipPath></defs></svg>
|
After Width: | Height: | Size: 5.8 KiB |
19
sample/file_example.svg
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<svg width="635.62" height="444.00" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="571.62" height="380.00" fill="#ffffff" rx="12.00" ry="12.00" filter="url(#shadow)" stroke="#e1e4e8" stroke-width="2.00" x="30.00px" y="30.00px"/>
|
||||
<g font-family="JetBrains Mono" font-size="16.00px" fill="#-00001" clip-path="url(#terminalMask)">
|
||||
<text x="70.00px" y="107.40px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 1 </tspan><tspan fill="#cf222e">use</tspan><tspan fill="#ffffff"> </tspan>std::collections::HashMap<tspan fill="#1f2328">;</tspan><tspan fill="#ffffff">
|
||||
</tspan></text><text x="70.00px" y="129.80px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 2 </tspan><tspan fill="#ffffff">
|
||||
</tspan></text><text x="70.00px" y="152.20px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 3 </tspan><tspan fill="#ffffff"/><tspan fill="#cf222e">fn</tspan> <tspan fill="#6639ba">main</tspan><tspan fill="#1f2328">()</tspan><tspan fill="#ffffff"> </tspan><tspan fill="#1f2328">{</tspan><tspan fill="#ffffff">
|
||||
</tspan></text><text x="70.00px" y="174.60px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 4 </tspan><tspan fill="#ffffff"> </tspan><tspan fill="#cf222e">let</tspan><tspan fill="#ffffff"> </tspan><tspan fill="#cf222e">mut</tspan><tspan fill="#ffffff"> </tspan>scores<tspan fill="#ffffff"> </tspan><tspan fill="#0550ae">=</tspan><tspan fill="#ffffff"> </tspan>HashMap::new<tspan fill="#1f2328">();</tspan><tspan fill="#ffffff">
|
||||
</tspan></text><text x="70.00px" y="197.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 5 </tspan><tspan fill="#ffffff">
|
||||
</tspan></text><text x="70.00px" y="219.40px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 6 </tspan><tspan fill="#ffffff"> </tspan>scores<tspan fill="#1f2328">.</tspan>insert<tspan fill="#1f2328">(</tspan><tspan fill="#6639ba">String</tspan>::from<tspan fill="#1f2328">(</tspan><tspan fill="#0a3069">"Blue"</tspan><tspan fill="#1f2328">),</tspan><tspan fill="#ffffff"> </tspan><tspan fill="#0550ae">10</tspan><tspan fill="#1f2328">);</tspan><tspan fill="#ffffff">
|
||||
</tspan></text><text x="70.00px" y="241.80px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 7 </tspan><tspan fill="#ffffff"> </tspan>scores<tspan fill="#1f2328">.</tspan>insert<tspan fill="#1f2328">(</tspan><tspan fill="#6639ba">String</tspan>::from<tspan fill="#1f2328">(</tspan><tspan fill="#0a3069">"Yellow"</tspan><tspan fill="#1f2328">),</tspan><tspan fill="#ffffff"> </tspan><tspan fill="#0550ae">50</tspan><tspan fill="#1f2328">);</tspan><tspan fill="#ffffff">
|
||||
</tspan></text><text x="70.00px" y="264.20px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 8 </tspan><tspan fill="#ffffff">
|
||||
</tspan></text><text x="70.00px" y="286.60px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 9 </tspan><tspan fill="#ffffff"> </tspan><tspan fill="#cf222e">for</tspan><tspan fill="#ffffff"> </tspan><tspan fill="#1f2328">(</tspan>key<tspan fill="#1f2328">,</tspan><tspan fill="#ffffff"> </tspan>value<tspan fill="#1f2328">)</tspan><tspan fill="#ffffff"> </tspan><tspan fill="#cf222e">in</tspan><tspan fill="#ffffff"> </tspan><tspan fill="#0550ae">&</tspan>scores<tspan fill="#ffffff"> </tspan><tspan fill="#1f2328">{</tspan><tspan fill="#ffffff">
|
||||
</tspan></text><text x="70.00px" y="309.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 10 </tspan><tspan fill="#ffffff"> </tspan><tspan fill="#6639ba">println!</tspan><tspan fill="#1f2328">(</tspan><tspan fill="#0a3069">"</tspan><tspan fill="#0a3069">{}</tspan><tspan fill="#0a3069">: </tspan><tspan fill="#0a3069">{}</tspan><tspan fill="#0a3069">"</tspan><tspan fill="#1f2328">,</tspan><tspan fill="#ffffff"> </tspan>key<tspan fill="#1f2328">,</tspan><tspan fill="#ffffff"> </tspan>value<tspan fill="#1f2328">);</tspan><tspan fill="#ffffff">
|
||||
</tspan></text><text x="70.00px" y="331.40px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 11 </tspan><tspan fill="#ffffff"> </tspan><tspan fill="#1f2328">}</tspan><tspan fill="#ffffff">
|
||||
</tspan></text><text x="70.00px" y="353.80px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 12 </tspan><tspan fill="#ffffff"/><tspan fill="#1f2328">}</tspan></text>
|
||||
</g>
|
||||
<svg x="30.00px" y="30.00px"><circle cx="13.50" cy="12.00" r="5.50" fill="#FF5A54"/><circle cx="32.50" cy="12.00" r="5.50" fill="#E6BF29"/><circle cx="51.50" cy="12.00" r="5.50" fill="#52C12B"/></svg><defs><filter id="shadow" filterUnits="userSpaceOnUse"><feGaussianBlur in="SourceAlpha" stdDeviation="30.00"/><feOffset result="offsetblur" dx="0.00" dy="15.00"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge></filter></defs></svg>
|
After Width: | Height: | Size: 4.9 KiB |
329
sample/main.go
Normal file
@@ -0,0 +1,329 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/landaiqing/freezelib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("🎨 Freeze Library Examples")
|
||||
fmt.Println("========================")
|
||||
|
||||
// Run all examples
|
||||
basicExample()
|
||||
quickFreezeExample()
|
||||
terminalExample()
|
||||
customConfigExample()
|
||||
fileExample()
|
||||
presetExample()
|
||||
chainedExample()
|
||||
|
||||
fmt.Println("\n✅ All examples completed successfully!")
|
||||
fmt.Println("Check the generated files in the current directory.")
|
||||
}
|
||||
|
||||
func basicExample() {
|
||||
fmt.Println("\n📝 Basic Example")
|
||||
fmt.Println("----------------")
|
||||
|
||||
// Create a new freeze instance
|
||||
freeze := freezelib.New()
|
||||
|
||||
// Go code to screenshot
|
||||
code := `package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello, World!")
|
||||
fmt.Println("This is a beautiful code screenshot!")
|
||||
}`
|
||||
|
||||
// Generate SVG
|
||||
svgData, err := freeze.GenerateFromCode(code, "go")
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Save to file
|
||||
err = os.WriteFile("basic_example.svg", svgData, 0644)
|
||||
if err != nil {
|
||||
fmt.Printf("Error saving file: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✓ Generated basic_example.svg")
|
||||
}
|
||||
|
||||
func quickFreezeExample() {
|
||||
fmt.Println("\n⚡ QuickFreeze Example")
|
||||
fmt.Println("---------------------")
|
||||
|
||||
// Use QuickFreeze for simplified API
|
||||
qf := freezelib.NewQuickFreeze()
|
||||
|
||||
// JavaScript code with styling
|
||||
code := `function fibonacci(n) {
|
||||
if (n <= 1) return n;
|
||||
return fibonacci(n - 1) + fibonacci(n - 2);
|
||||
}
|
||||
|
||||
console.log('Fibonacci sequence:');
|
||||
for (let i = 0; i < 10; i++) {
|
||||
console.log('F(' + i + ') = ' + fibonacci(i));
|
||||
}`
|
||||
|
||||
// Chain styling options
|
||||
svgData, err := qf.WithTheme("dracula").
|
||||
WithFont("Fira Code", 14).
|
||||
WithWindow().
|
||||
WithShadow().
|
||||
WithLineNumbers().
|
||||
WithLanguage("javascript").
|
||||
CodeToSVG(code)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = os.WriteFile("quickfreeze_example.svg", svgData, 0644)
|
||||
if err != nil {
|
||||
fmt.Printf("Error saving file: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✓ Generated quickfreeze_example.svg")
|
||||
}
|
||||
|
||||
func terminalExample() {
|
||||
fmt.Println("\n💻 Terminal Example")
|
||||
fmt.Println("-------------------")
|
||||
|
||||
// Use terminal preset for ANSI output
|
||||
freeze := freezelib.NewWithConfig(freezelib.TerminalPreset())
|
||||
|
||||
// Colored terminal output
|
||||
terminalOutput := "\033[32m✓ SUCCESS\033[0m: Build completed successfully\n" +
|
||||
"\033[33m⚠ WARNING\033[0m: Deprecated function used in main.go:42\n" +
|
||||
"\033[31m✗ ERROR\033[0m: File not found: config.json\n" +
|
||||
"\033[36mINFO\033[0m: Starting server on port 8080\n" +
|
||||
"\033[35mDEBUG\033[0m: Loading configuration from ~/.config/app"
|
||||
|
||||
svgData, err := freeze.GenerateFromANSI(terminalOutput)
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = os.WriteFile("terminal_example.svg", svgData, 0644)
|
||||
if err != nil {
|
||||
fmt.Printf("Error saving file: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✓ Generated terminal_example.svg")
|
||||
}
|
||||
|
||||
func customConfigExample() {
|
||||
fmt.Println("\n⚙️ Custom Config Example")
|
||||
fmt.Println("-------------------------")
|
||||
|
||||
// Create custom configuration
|
||||
config := freezelib.DefaultConfig()
|
||||
|
||||
// Customize appearance
|
||||
config.Theme = "github"
|
||||
config.Background = "#f6f8fa"
|
||||
config.Font.Family = "JetBrains Mono"
|
||||
config.Font.Size = 16
|
||||
config.LineHeight = 1.4
|
||||
|
||||
// Layout settings
|
||||
config.SetPadding(30)
|
||||
config.SetMargin(20)
|
||||
config.Width = 800
|
||||
|
||||
// Effects
|
||||
config.Window = true
|
||||
config.ShowLineNumbers = true
|
||||
config.Border.Radius = 12
|
||||
config.Border.Width = 2
|
||||
config.Border.Color = "#d1d9e0"
|
||||
config.Shadow.Blur = 25
|
||||
config.Shadow.Y = 15
|
||||
|
||||
// Create freeze instance with custom config
|
||||
freeze := freezelib.NewWithConfig(config)
|
||||
|
||||
// Python code
|
||||
code := `import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
def plot_sine_wave():
|
||||
x = np.linspace(0, 2 * np.pi, 100)
|
||||
y = np.sin(x)
|
||||
|
||||
plt.figure(figsize=(10, 6))
|
||||
plt.plot(x, y, 'b-', linewidth=2, label='sin(x)')
|
||||
plt.xlabel('x')
|
||||
plt.ylabel('sin(x)')
|
||||
plt.title('Sine Wave')
|
||||
plt.grid(True, alpha=0.3)
|
||||
plt.legend()
|
||||
plt.show()
|
||||
|
||||
if __name__ == "__main__":
|
||||
plot_sine_wave()`
|
||||
|
||||
svgData, err := freeze.GenerateFromCode(code, "python")
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = os.WriteFile("custom_config_example.svg", svgData, 0644)
|
||||
if err != nil {
|
||||
fmt.Printf("Error saving file: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✓ Generated custom_config_example.svg")
|
||||
}
|
||||
|
||||
func fileExample() {
|
||||
fmt.Println("\n📁 File Example")
|
||||
fmt.Println("---------------")
|
||||
|
||||
// Create a sample Rust file
|
||||
sampleCode := `use std::collections::HashMap;
|
||||
|
||||
fn main() {
|
||||
let mut scores = HashMap::new();
|
||||
|
||||
scores.insert(String::from("Blue"), 10);
|
||||
scores.insert(String::from("Yellow"), 50);
|
||||
|
||||
for (key, value) in &scores {
|
||||
println!("{}: {}", key, value);
|
||||
}
|
||||
}`
|
||||
|
||||
// Create sample file
|
||||
err := os.WriteFile("sample.rs", []byte(sampleCode), 0644)
|
||||
if err != nil {
|
||||
fmt.Printf("Error creating sample file: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Use presentation preset
|
||||
freeze := freezelib.NewWithConfig(freezelib.PresentationPreset())
|
||||
|
||||
// Generate from file
|
||||
svgData, err := freeze.GenerateFromFile("sample.rs")
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = os.WriteFile("file_example.svg", svgData, 0644)
|
||||
if err != nil {
|
||||
fmt.Printf("Error saving file: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✓ Generated file_example.svg")
|
||||
fmt.Println("✓ Created sample.rs")
|
||||
}
|
||||
|
||||
func presetExample() {
|
||||
fmt.Println("\n🎨 Preset Example")
|
||||
fmt.Println("-----------------")
|
||||
|
||||
code := `const express = require('express');
|
||||
const app = express();
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.json({ message: 'Hello, World!' });
|
||||
});
|
||||
|
||||
app.listen(3000, () => {
|
||||
console.log('Server running on port 3000');
|
||||
});`
|
||||
|
||||
// Try different presets
|
||||
presets := []string{"dark", "light", "minimal", "retro"}
|
||||
|
||||
for _, preset := range presets {
|
||||
freeze := freezelib.NewWithPreset(preset)
|
||||
svgData, err := freeze.GenerateFromCode(code, "javascript")
|
||||
if err != nil {
|
||||
fmt.Printf("Error with preset %s: %v\n", preset, err)
|
||||
continue
|
||||
}
|
||||
|
||||
filename := fmt.Sprintf("preset_%s_example.svg", preset)
|
||||
err = os.WriteFile(filename, svgData, 0644)
|
||||
if err != nil {
|
||||
fmt.Printf("Error saving %s: %v\n", filename, err)
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Printf("✓ Generated %s\n", filename)
|
||||
}
|
||||
}
|
||||
|
||||
func chainedExample() {
|
||||
fmt.Println("\n🔗 Chained Methods Example")
|
||||
fmt.Println("---------------------------")
|
||||
|
||||
// Create base freeze instance
|
||||
freeze := freezelib.New()
|
||||
|
||||
code := `#include <iostream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
int main() {
|
||||
std::vector<int> numbers = {5, 2, 8, 1, 9};
|
||||
|
||||
std::sort(numbers.begin(), numbers.end());
|
||||
|
||||
std::cout << "Sorted numbers: ";
|
||||
for (const auto& num : numbers) {
|
||||
std::cout << num << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
return 0;
|
||||
}`
|
||||
|
||||
// Chain multiple styling methods
|
||||
svgData, err := freeze.
|
||||
WithTheme("monokai").
|
||||
WithFont("Cascadia Code", 15).
|
||||
WithBackground("#2d2d2d").
|
||||
WithWindow(true).
|
||||
WithLineNumbers(true).
|
||||
WithShadow(20, 0, 10).
|
||||
WithBorder(1, 10, "#444444").
|
||||
WithPadding(25).
|
||||
WithMargin(15).
|
||||
GenerateFromCode(code, "cpp")
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = os.WriteFile("chained_example.svg", svgData, 0644)
|
||||
if err != nil {
|
||||
fmt.Printf("Error saving file: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✓ Generated chained_example.svg")
|
||||
}
|
17
sample/preset_dark_example.svg
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<svg width="463.33" height="274.00" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="431.33" height="242.00" fill="#282a36" rx="8.00" ry="8.00" filter="url(#shadow)" stroke="#3c3c3c" stroke-width="1.00" x="15.00px" y="15.00px"/>
|
||||
<g font-family="Fira Code" font-size="14.00px" fill="#f8f8f2" clip-path="url(#terminalMask)">
|
||||
<text x="40.00px" y="56.80px" xml:space="preserve"><tspan fill="#ff79c6">const</tspan> express <tspan fill="#ff79c6">=</tspan> require(<tspan fill="#f1fa8c">'express'</tspan>);
|
||||
</text><text x="40.00px" y="73.60px" xml:space="preserve"><tspan fill="#ff79c6">const</tspan> app <tspan fill="#ff79c6">=</tspan> express();
|
||||
</text><text x="40.00px" y="90.40px" xml:space="preserve">
|
||||
</text><text x="40.00px" y="107.20px" xml:space="preserve">app.get(<tspan fill="#f1fa8c">'/'</tspan>, (req, res) => {
|
||||
</text><text x="40.00px" y="124.00px" xml:space="preserve"> res.json({ message<tspan fill="#ff79c6">:</tspan> <tspan fill="#f1fa8c">'Hello, World!'</tspan> });
|
||||
</text><text x="40.00px" y="140.80px" xml:space="preserve">});
|
||||
</text><text x="40.00px" y="157.60px" xml:space="preserve">
|
||||
</text><text x="40.00px" y="174.40px" xml:space="preserve">app.listen(<tspan fill="#bd93f9">3000</tspan>, () => {
|
||||
</text><text x="40.00px" y="191.20px" xml:space="preserve"> console.log(<tspan fill="#f1fa8c">'Server running on port 3000'</tspan>);
|
||||
</text><text x="40.00px" y="208.00px" xml:space="preserve">});</text>
|
||||
</g>
|
||||
<defs><filter id="shadow" filterUnits="userSpaceOnUse"><feGaussianBlur in="SourceAlpha" stdDeviation="20.00"/><feOffset result="offsetblur" dx="0.00" dy="8.00"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge></filter></defs></svg>
|
After Width: | Height: | Size: 1.8 KiB |
17
sample/preset_light_example.svg
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<svg width="463.33" height="274.00" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="431.33" height="242.00" fill="#ffffff" rx="8.00" ry="8.00" filter="url(#shadow)" stroke="#d1d5da" stroke-width="1.00" x="15.00px" y="15.00px"/>
|
||||
<g font-family="SF Mono" font-size="14.00px" fill="#-00001" clip-path="url(#terminalMask)">
|
||||
<text x="40.00px" y="56.80px" xml:space="preserve"><tspan fill="#cf222e">const</tspan> <tspan fill="#1f2328">express</tspan> <tspan fill="#0550ae">=</tspan> <tspan fill="#1f2328">require</tspan><tspan fill="#1f2328">(</tspan><tspan fill="#0a3069">'express'</tspan><tspan fill="#1f2328">);</tspan>
|
||||
</text><text x="40.00px" y="73.60px" xml:space="preserve"><tspan fill="#cf222e">const</tspan> <tspan fill="#1f2328">app</tspan> <tspan fill="#0550ae">=</tspan> <tspan fill="#1f2328">express</tspan><tspan fill="#1f2328">();</tspan>
|
||||
</text><text x="40.00px" y="90.40px" xml:space="preserve">
|
||||
</text><text x="40.00px" y="107.20px" xml:space="preserve"><tspan fill="#1f2328">app</tspan><tspan fill="#1f2328">.</tspan><tspan fill="#1f2328">get</tspan><tspan fill="#1f2328">(</tspan><tspan fill="#0a3069">'/'</tspan><tspan fill="#1f2328">,</tspan> <tspan fill="#1f2328">(</tspan><tspan fill="#1f2328">req</tspan><tspan fill="#1f2328">,</tspan> <tspan fill="#1f2328">res</tspan><tspan fill="#1f2328">)</tspan> <tspan fill="#1f2328">=></tspan> <tspan fill="#1f2328">{</tspan>
|
||||
</text><text x="40.00px" y="124.00px" xml:space="preserve"> <tspan fill="#1f2328">res</tspan><tspan fill="#1f2328">.</tspan><tspan fill="#1f2328">json</tspan><tspan fill="#1f2328">({</tspan> <tspan fill="#1f2328">message</tspan><tspan fill="#0550ae">:</tspan> <tspan fill="#0a3069">'Hello, World!'</tspan> <tspan fill="#1f2328">});</tspan>
|
||||
</text><text x="40.00px" y="140.80px" xml:space="preserve"><tspan fill="#1f2328">});</tspan>
|
||||
</text><text x="40.00px" y="157.60px" xml:space="preserve">
|
||||
</text><text x="40.00px" y="174.40px" xml:space="preserve"><tspan fill="#1f2328">app</tspan><tspan fill="#1f2328">.</tspan><tspan fill="#1f2328">listen</tspan><tspan fill="#1f2328">(</tspan><tspan fill="#0550ae">3000</tspan><tspan fill="#1f2328">,</tspan> <tspan fill="#1f2328">()</tspan> <tspan fill="#1f2328">=></tspan> <tspan fill="#1f2328">{</tspan>
|
||||
</text><text x="40.00px" y="191.20px" xml:space="preserve"> <tspan fill="#1f2328">console</tspan><tspan fill="#1f2328">.</tspan><tspan fill="#1f2328">log</tspan><tspan fill="#1f2328">(</tspan><tspan fill="#0a3069">'Server running on port 3000'</tspan><tspan fill="#1f2328">);</tspan>
|
||||
</text><text x="40.00px" y="208.00px" xml:space="preserve"><tspan fill="#1f2328">});</tspan></text>
|
||||
</g>
|
||||
<defs><filter id="shadow" filterUnits="userSpaceOnUse"><feGaussianBlur in="SourceAlpha" stdDeviation="20.00"/><feOffset result="offsetblur" dx="0.00" dy="8.00"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge></filter></defs></svg>
|
After Width: | Height: | Size: 3.0 KiB |
17
sample/preset_minimal_example.svg
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<svg width="403.33" height="214.00" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="403.33" height="214.00" fill="#ffffff" x="0.00px" y="0.00px"/>
|
||||
<g font-family="JetBrains Mono" font-size="14.00px" fill="#-00001" clip-path="url(#terminalMask)">
|
||||
<text x="10.00px" y="26.80px" xml:space="preserve"><tspan fill="#cf222e">const</tspan> <tspan fill="#1f2328">express</tspan> <tspan fill="#0550ae">=</tspan> <tspan fill="#1f2328">require</tspan><tspan fill="#1f2328">(</tspan><tspan fill="#0a3069">'express'</tspan><tspan fill="#1f2328">);</tspan>
|
||||
</text><text x="10.00px" y="43.60px" xml:space="preserve"><tspan fill="#cf222e">const</tspan> <tspan fill="#1f2328">app</tspan> <tspan fill="#0550ae">=</tspan> <tspan fill="#1f2328">express</tspan><tspan fill="#1f2328">();</tspan>
|
||||
</text><text x="10.00px" y="60.40px" xml:space="preserve">
|
||||
</text><text x="10.00px" y="77.20px" xml:space="preserve"><tspan fill="#1f2328">app</tspan><tspan fill="#1f2328">.</tspan><tspan fill="#1f2328">get</tspan><tspan fill="#1f2328">(</tspan><tspan fill="#0a3069">'/'</tspan><tspan fill="#1f2328">,</tspan> <tspan fill="#1f2328">(</tspan><tspan fill="#1f2328">req</tspan><tspan fill="#1f2328">,</tspan> <tspan fill="#1f2328">res</tspan><tspan fill="#1f2328">)</tspan> <tspan fill="#1f2328">=></tspan> <tspan fill="#1f2328">{</tspan>
|
||||
</text><text x="10.00px" y="94.00px" xml:space="preserve"> <tspan fill="#1f2328">res</tspan><tspan fill="#1f2328">.</tspan><tspan fill="#1f2328">json</tspan><tspan fill="#1f2328">({</tspan> <tspan fill="#1f2328">message</tspan><tspan fill="#0550ae">:</tspan> <tspan fill="#0a3069">'Hello, World!'</tspan> <tspan fill="#1f2328">});</tspan>
|
||||
</text><text x="10.00px" y="110.80px" xml:space="preserve"><tspan fill="#1f2328">});</tspan>
|
||||
</text><text x="10.00px" y="127.60px" xml:space="preserve">
|
||||
</text><text x="10.00px" y="144.40px" xml:space="preserve"><tspan fill="#1f2328">app</tspan><tspan fill="#1f2328">.</tspan><tspan fill="#1f2328">listen</tspan><tspan fill="#1f2328">(</tspan><tspan fill="#0550ae">3000</tspan><tspan fill="#1f2328">,</tspan> <tspan fill="#1f2328">()</tspan> <tspan fill="#1f2328">=></tspan> <tspan fill="#1f2328">{</tspan>
|
||||
</text><text x="10.00px" y="161.20px" xml:space="preserve"> <tspan fill="#1f2328">console</tspan><tspan fill="#1f2328">.</tspan><tspan fill="#1f2328">log</tspan><tspan fill="#1f2328">(</tspan><tspan fill="#0a3069">'Server running on port 3000'</tspan><tspan fill="#1f2328">);</tspan>
|
||||
</text><text x="10.00px" y="178.00px" xml:space="preserve"><tspan fill="#1f2328">});</tspan></text>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.7 KiB |
17
sample/preset_retro_example.svg
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<svg width="388.57" height="226.29" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="364.57" height="202.29" fill="#272822" stroke="#00ff00" stroke-width="2.00" x="10.00px" y="10.00px"/>
|
||||
<g font-family="Courier New" font-size="12.00px" fill="#f8f8f2" clip-path="url(#terminalMask)">
|
||||
<text x="30.00px" y="44.40px" xml:space="preserve"><tspan fill="#66d9ef">const</tspan> <tspan fill="#a6e22e">express</tspan> <tspan fill="#f92672">=</tspan> <tspan fill="#a6e22e">require</tspan>(<tspan fill="#e6db74">'express'</tspan>);
|
||||
</text><text x="30.00px" y="58.80px" xml:space="preserve"><tspan fill="#66d9ef">const</tspan> <tspan fill="#a6e22e">app</tspan> <tspan fill="#f92672">=</tspan> <tspan fill="#a6e22e">express</tspan>();
|
||||
</text><text x="30.00px" y="73.20px" xml:space="preserve">
|
||||
</text><text x="30.00px" y="87.60px" xml:space="preserve"><tspan fill="#a6e22e">app</tspan>.<tspan fill="#a6e22e">get</tspan>(<tspan fill="#e6db74">'/'</tspan>, (<tspan fill="#a6e22e">req</tspan>, <tspan fill="#a6e22e">res</tspan>) => {
|
||||
</text><text x="30.00px" y="102.00px" xml:space="preserve"> <tspan fill="#a6e22e">res</tspan>.<tspan fill="#a6e22e">json</tspan>({ <tspan fill="#a6e22e">message</tspan><tspan fill="#f92672">:</tspan> <tspan fill="#e6db74">'Hello, World!'</tspan> });
|
||||
</text><text x="30.00px" y="116.40px" xml:space="preserve">});
|
||||
</text><text x="30.00px" y="130.80px" xml:space="preserve">
|
||||
</text><text x="30.00px" y="145.20px" xml:space="preserve"><tspan fill="#a6e22e">app</tspan>.<tspan fill="#a6e22e">listen</tspan>(<tspan fill="#ae81ff">3000</tspan>, () => {
|
||||
</text><text x="30.00px" y="159.60px" xml:space="preserve"> <tspan fill="#a6e22e">console</tspan>.<tspan fill="#a6e22e">log</tspan>(<tspan fill="#e6db74">'Server running on port 3000'</tspan>);
|
||||
</text><text x="30.00px" y="174.00px" xml:space="preserve">});</text>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.0 KiB |
16
sample/quickfreeze_example.svg
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<svg width="507.00" height="218.00" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="507.00" height="218.00" fill="#282a36" filter="url(#shadow)" x="0.00px" y="0.00px"/>
|
||||
<g font-family="Fira Code" font-size="14.00px" fill="#f8f8f2" clip-path="url(#terminalMask)">
|
||||
<text x="20.00px" y="51.80px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 1 </tspan><tspan fill="#8be9fd" font-style="italic">function</tspan> fibonacci(n) {
|
||||
</text><text x="20.00px" y="68.60px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 2 </tspan> <tspan fill="#ff79c6">if</tspan> (n <tspan fill="#ff79c6"><=</tspan> <tspan fill="#bd93f9">1</tspan>) <tspan fill="#ff79c6">return</tspan> n;
|
||||
</text><text x="20.00px" y="85.40px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 3 </tspan> <tspan fill="#ff79c6">return</tspan> fibonacci(n <tspan fill="#ff79c6">-</tspan> <tspan fill="#bd93f9">1</tspan>) <tspan fill="#ff79c6">+</tspan> fibonacci(n <tspan fill="#ff79c6">-</tspan> <tspan fill="#bd93f9">2</tspan>);
|
||||
</text><text x="20.00px" y="102.20px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 4 </tspan>}
|
||||
</text><text x="20.00px" y="119.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 5 </tspan>
|
||||
</text><text x="20.00px" y="135.80px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 6 </tspan>console.log(<tspan fill="#f1fa8c">'Fibonacci sequence:'</tspan>);
|
||||
</text><text x="20.00px" y="152.60px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 7 </tspan><tspan fill="#ff79c6">for</tspan> (<tspan fill="#8be9fd" font-style="italic">let</tspan> i <tspan fill="#ff79c6">=</tspan> <tspan fill="#bd93f9">0</tspan>; i <tspan fill="#ff79c6"><</tspan> <tspan fill="#bd93f9">10</tspan>; i<tspan fill="#ff79c6">++</tspan>) {
|
||||
</text><text x="20.00px" y="169.40px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 8 </tspan> console.log(<tspan fill="#f1fa8c">'F('</tspan> <tspan fill="#ff79c6">+</tspan> i <tspan fill="#ff79c6">+</tspan> <tspan fill="#f1fa8c">') = '</tspan> <tspan fill="#ff79c6">+</tspan> fibonacci(i));
|
||||
</text><text x="20.00px" y="186.20px" xml:space="preserve"><tspan xml:space="preserve" fill="#7f7f7f"> 9 </tspan>}</text>
|
||||
</g>
|
||||
<svg x="0.00px" y="0.00px"><circle cx="13.50" cy="12.00" r="5.50" fill="#FF5A54"/><circle cx="32.50" cy="12.00" r="5.50" fill="#E6BF29"/><circle cx="51.50" cy="12.00" r="5.50" fill="#52C12B"/></svg><defs><filter id="shadow" filterUnits="userSpaceOnUse"><feGaussianBlur in="SourceAlpha" stdDeviation="20.00"/><feOffset result="offsetblur" dx="0.00" dy="10.00"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge></filter></defs></svg>
|
After Width: | Height: | Size: 2.9 KiB |
12
sample/sample.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
fn main() {
|
||||
let mut scores = HashMap::new();
|
||||
|
||||
scores.insert(String::from("Blue"), 10);
|
||||
scores.insert(String::from("Yellow"), 50);
|
||||
|
||||
for (key, value) in &scores {
|
||||
println!("{}: {}", key, value);
|
||||
}
|
||||
}
|
81
sample/simple_test.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/landaiqing/freezelib"
|
||||
"os"
|
||||
)
|
||||
|
||||
func simpleTest() {
|
||||
fmt.Println("🧪 Simple Test")
|
||||
fmt.Println("==============")
|
||||
|
||||
// Create a new freeze instance
|
||||
freeze := freezelib.New()
|
||||
|
||||
// Simple Go code to test
|
||||
code := `package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello from FreezeLib!")
|
||||
}`
|
||||
|
||||
// Generate SVG
|
||||
svgData, err := freeze.GenerateFromCode(code, "go")
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Save to file
|
||||
err = os.WriteFile("simple_test.svg", svgData, 0644)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error saving file: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("✅ Generated simple_test.svg (%d bytes)\n", len(svgData))
|
||||
|
||||
// Test QuickFreeze API
|
||||
qf := freezelib.NewQuickFreeze()
|
||||
svgData2, err := qf.WithTheme("github").CodeToSVG(code)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ QuickFreeze Error: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = os.WriteFile("quickfreeze_test.svg", svgData2, 0644)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error saving QuickFreeze file: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("✅ Generated quickfreeze_test.svg (%d bytes)\n", len(svgData2))
|
||||
|
||||
// Test ANSI output
|
||||
ansiOutput := "\033[32m✓ SUCCESS\033[0m: Test passed\n\033[31m✗ ERROR\033[0m: Test failed"
|
||||
ansiData, err := freeze.GenerateFromANSI(ansiOutput)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ ANSI Error: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = os.WriteFile("ansi_test.svg", ansiData, 0644)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error saving ANSI file: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("✅ Generated ansi_test.svg (%d bytes)\n", len(ansiData))
|
||||
fmt.Println("🎉 All tests passed!")
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Run simple test instead of full examples
|
||||
if len(os.Args) > 1 && os.Args[1] == "test" {
|
||||
simpleTest()
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
8
sample/terminal_example.svg
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<svg width="436.90" height="152.14" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="414.90" height="130.14" fill="#0d1117" rx="6.00" ry="6.00" filter="url(#shadow)" stroke="#30363d" stroke-width="1.00" x="10.00px" y="10.00px"/>
|
||||
<g font-family="JetBrains Mono" font-size="13.00px" fill="#e6edf3" clip-path="url(#terminalMask)">
|
||||
<text x="25.00px" y="40.60px" xml:space="preserve"><tspan xml:space="preserve" fill="#00FF00">✓ SUCCESS</tspan><tspan xml:space="preserve">: Build completed successfully</tspan></text><text x="25.00px" y="56.20px" xml:space="preserve"><tspan xml:space="preserve" fill="#FFFF00">⚠ WARNING</tspan><tspan xml:space="preserve">: Deprecated function used in main.go:42</tspan></text><text x="25.00px" y="71.80px" xml:space="preserve"><tspan xml:space="preserve" fill="#FF0000">✗ ERROR</tspan><tspan xml:space="preserve">: File not found: config.json</tspan></text><text x="25.00px" y="87.40px" xml:space="preserve"><tspan xml:space="preserve" fill="#00FFFF">INFO</tspan><tspan xml:space="preserve">: Starting server on port 8080</tspan></text><text x="25.00px" y="103.00px" xml:space="preserve"><tspan xml:space="preserve" fill="#FF00FF">DEBUG</tspan><tspan xml:space="preserve">: Loading configuration from ~/.config/app</tspan></text>
|
||||
</g>
|
||||
<defs><filter id="shadow" filterUnits="userSpaceOnUse"><feGaussianBlur in="SourceAlpha" stdDeviation="15.00"/><feOffset result="offsetblur" dx="0.00" dy="5.00"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge></filter></defs></svg>
|
After Width: | Height: | Size: 1.6 KiB |