summary refs log blame commit diff stats
path: root/pkg/background/background.go
blob: c6000ff48c6b67ca52b7637b90ada0047769be80 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16















                                                                           

                








                                                        
// Copyright (c) 2020, Andinus <andinus@inventati.org>

// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.

// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

package background

import "os/exec"

// Set calls feh to set the background
func Set(path string) error {
	feh, err := exec.LookPath("feh")
	if err != nil {
		return err
	}
	err = exec.Command(feh, "--bg-fill", path).Run()
	return err
}
id=4a48bedcd1d708a43d43dc6259a4e45c52ea3d00'>4a48bedc ^
b96af395 ^

9458918f ^
5b22547b ^
b96af395 ^
08f4628e ^
b96af395 ^

f192d655 ^
b96af395 ^
f192d655 ^
1ead3562 ^
77d5b5d6 ^
760f683f ^
b96af395 ^
192d59d3 ^

ce87c19e ^

b96af395 ^
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

                                                                
                                                   
                                          
             
             
         
                  
   
                                  
                      
                                                  
                             
 
                         
                 
        
   
            
 
 
                                                           
                                             
             
             

                                      
                                            
                 
                                                  
                                  

        
   
 
 
          
             
                                                                  
                                                                  

                                                

                           
 
# example program: communicating between routines using channels

def producer sink:&:sink:char -> sink:&:sink:char [
  # produce characters 1 to 5 on a channel
  local-scope
  load-inputs
  # n = 0
  n:char <- copy 0
  {
    done?:bool <- lesser-than n, 5
    break-unless done?
    # other threads might get between these prints
    $print [produce: ], n, [ 
]
    sink <- write sink, n
    n <- add n, 1
    loop
  }
  close sink
]

def consumer source:&:source:char -> source:&:source:char [
  # consume and print integers from a channel
  local-scope
  load-inputs
  {
    # read an integer from the channel
    n:char, eof?:bool, source <- read source
    break-if eof?
    # other threads might get between these prints
    $print [consume: ], n:char, [ 
]
    loop
  }
]

def main [
  local-scope
  source:&:source:char, sink:&:sink:char <- new-channel 3/capacity
  # create two background 'routines' that communicate by a channel
  routine1:num <- start-running producer, sink
  routine2:num <- start-running consumer, source
  wait-for-routine routine1
  wait-for-routine routine2
]