summary refs log tree commit diff stats
path: root/commands/account/view.go
blob: cec65aa9c6d60061a2e7534058c3a306f4bc1111 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package account

import (
	"errors"

	"git.sr.ht/~sircmpwn/aerc/widgets"
)

type ViewMessage struct{}

func init() {
	register(ViewMessage{})
}

func (_ ViewMessage) Aliases() []string {
	return []string{"view-message", "view"}
}

func (_ ViewMessage) Complete(aerc *widgets.Aerc, args []string) []string {
	return nil
}

func (_ ViewMessage) Execute(aerc *widgets.Aerc, args []string) error {
	if len(args) != 1 {
		return errors.New("Usage: view-message")
	}
	acct := aerc.SelectedAccount()
	if acct.Messages().Empty() {
		return nil
	}
	store := acct.Messages().Store()
	msg := acct.Messages().Selected()
	if msg == nil {
		return nil
	}
	viewer := widgets.NewMessageViewer(acct, aerc.Config(), store, msg)
	aerc.NewTab(viewer, msg.Envelope.Subject)
	return nil
}
nus <andinus@nand.sh> 2021-11-03 20:20:07 +0530 Parse fornax format to generate the images' href='/andinus/fornax/commit/lib/Fornax/CLI.rakumod?h=v0.2.0&id=4e8a59668535badfe7e1975f52fb04489e467585'>4e8a596 ^
bffe38e ^
74fa056 ^
4e8a596 ^
bffe38e ^
74fa056 ^
4e8a596 ^

eb96ab9 ^

a35769b ^
ddb0440 ^
4e8a596 ^
ddb0440 ^


1ef8b03 ^
ddb0440 ^
eb96ab9 ^






ddb0440 ^


eb96ab9 ^



a35769b ^

9fededa ^

ca74f0d ^
eb96ab9 ^



6b73ff7 ^
ed7cf1c ^
eb96ab9 ^
ed7cf1c ^
eb96ab9 ^
22aa1c9 ^
8af7ea1 ^
ed7cf1c ^

31e11e8 ^




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
                          
 
                                







                                                 
                                                                       


                                                           
                                               

                                                                              
                                                                              
                                             
                               
             
                                             
                                                          



                                                          
                                     
 

                                                           
                                                                 
 
                                               
 



                                                                      
 


                                       


                                                                
                                                                         
                             
            
                                                                        
                              

     

                                            
 
                  
                                             


                                                                    
                     
                    






                                                                        


                        



                                                                           

         

                                        
 



                                                                       
 
                        
                                             
 
                                                        
                                                                                   
                                                              

                                                                                      




                                                    
use Fornax::GenerateFrame;

subset File of Str where *.IO.f;

#| Parses fornax format file to extract metadata.
grammar Metadata {
    rule TOP {  <rows> <cols> }
    token rows { 'rows:' <(\d+)> }
    token cols { 'cols:' <(\d+)> }
}

proto MAIN(|) is export { unless so @*ARGS { put $*USAGE; exit }; {*} }

#| Collection of tools to visualize Path Finding Algorithms
multi sub MAIN(
    File $input, #= fornax format file (solved)

    Int() :$batch = 4, #= number of iterations to process at once (default: 4)
    Int() :fps($frame-rate) = 1, #= frame rate for video solution (default: 1)
    Bool :$skip-video, #= skip video solution
    Bool :$debug, #= debug logs
) is export {
    my IO() $output = "%s/fornax-%s".sprintf(
        '/tmp', ('a'...'z', 'A'...'Z', 0...9).roll(8).join
    );
    mkdir $output;
    die "Output directory doesn't exist" unless $output.d;

    put "[fornax] Output: '$output'";

    my Str @lines = $input.IO.lines;
    my Int() %meta{Str} = Metadata.parse(@lines.first).Hash
                                  or die "Cannot parse metadata";

    constant %CANVAS = :1920width, :1080height;

    # Every cell must be square. Get the maximum width, height and use
    # that to decide which is to be used.
    my Int %cell = width => %CANVAS<width> div %meta<cols>,
                   height => %CANVAS<height> div %meta<rows>;

    my Int $side;
    my Int %excess = :0width, :0height;

    # Consider width if cells with dimension (width * width) fit
    # within the canvas, otherwise consider the height.
    if (%cell<width> * %meta<rows>) < %CANVAS<height> {
        %excess<height> = %CANVAS<height> - (%cell<width> * %meta<rows>);
        $side = %cell<width>;
    } else {
        %excess<width> = %CANVAS<width> - (%cell<height> * %meta<cols>);
        $side = %cell<height>;
    }

    my $render-start = now;
    my Int $total-frames = @lines.elems - 1;

    my Promise @p;
    for @lines.skip.kv -> $idx, $iter is rw {
        # Wait until all scheduled jobs are finished, then empty the
        # array and continue.
        if @p.elems == $batch {
            await @p;
            @p = [];

            print "\r";
            print "%s  Remaining: %.2fs  Elapsed: %.2fs %s".sprintf(
                "[fornax $idx/$total-frames]",
                ((now - $render-start) / $idx) * ($total-frames - $idx),
                now - $render-start, "        ",
            );
        }

        push @p, start {
            generate-frame(
                :%CANVAS, :%excess, :$side, :%meta, :$iter, :$idx, :$debug,
                :out("%s/%08d.png".sprintf: $output, $idx),
            );
        }
    }
    # Wait for remaining jobs to finish.
    await @p;

    print "\r";
    put "[fornax] Generated $total-frames frames in %.2fs. %s".sprintf(
        now - $render-start, " " x 16,
    );

    unless $skip-video {
        put "[fornax] Creating a slideshow.";

        my Str $log-level = $debug ?? "info" !! "error";
        run «ffmpeg -loglevel "$log-level" -r "$frame-rate" -i "$output/\%08d.png"
                    -vf 'tpad=stop_mode=clone:stop_duration=2'
                    -vcodec libx264 -crf 28 -pix_fmt yuv420p "$output/solution.mp4"»;
    }
}

multi sub MAIN(
    Bool :$version #= print version
) { say "Fornax v" ~ $?DISTRIBUTION.meta<version>; }