Reformat with gofmt
This commit is contained in:
		
							parent
							
								
									66695e069b
								
							
						
					
					
						commit
						72916575bd
					
				
					 1 changed files with 17 additions and 19 deletions
				
			
		
							
								
								
									
										36
									
								
								Main.go
									
										
									
									
									
								
							
							
						
						
									
										36
									
								
								Main.go
									
										
									
									
									
								
							|  | @ -3,18 +3,17 @@ package main | ||||||
| import ( | import ( | ||||||
| 	"log" | 	"log" | ||||||
| 	"os" | 	"os" | ||||||
| 	"time" |  | ||||||
| 	"strconv" | 	"strconv" | ||||||
|  | 	"time" | ||||||
| 	"unicode/utf8" | 	"unicode/utf8" | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 	"github.com/gdamore/tcell/v2" | 	"github.com/gdamore/tcell/v2" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| const ( | const ( | ||||||
| 	dayWidth    = 2 | 	dayWidth    = 2 | ||||||
| 	smallGap    = 1 | 	smallGap    = 1 | ||||||
| 	largeGap = 3 | 	largeGap    = 3 | ||||||
| 	monthWidth  = 7*dayWidth + 6*smallGap | 	monthWidth  = 7*dayWidth + 6*smallGap | ||||||
| 	monthHeight = (31+6+(7-1))/7 + 2 | 	monthHeight = (31+6+(7-1))/7 + 2 | ||||||
| 	/* monthHeight is the height of a 31-day month starting on Sunday (month | 	/* monthHeight is the height of a 31-day month starting on Sunday (month | ||||||
|  | @ -31,7 +30,7 @@ var ( | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| var ( | var ( | ||||||
| 	wall tcell.Screen | 	wall     tcell.Screen | ||||||
| 	defStyle tcell.Style | 	defStyle tcell.Style | ||||||
| 	selStyle tcell.Style | 	selStyle tcell.Style | ||||||
| ) | ) | ||||||
|  | @ -60,14 +59,14 @@ func date(year int, month time.Month, day int) time.Time { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func centeredText(s string, x, y, width int, scr tcell.Screen, style tcell.Style) { | func centeredText(s string, x, y, width int, scr tcell.Screen, style tcell.Style) { | ||||||
| 	start := x + max((width - utf8.RuneCountInString(s)) / 2, 0) | 	start := x + max((width-utf8.RuneCountInString(s))/2, 0) | ||||||
| 	i := 0 | 	i := 0 | ||||||
| 	for _, char := range s { | 	for _, char := range s { | ||||||
| 		if i >= width { | 		if i >= width { | ||||||
| 			break; | 			break | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		scr.SetContent(start + i, y, char, nil, style) | 		scr.SetContent(start+i, y, char, nil, style) | ||||||
| 		i++ | 		i++ | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | @ -79,7 +78,7 @@ func wrappedText(s string, scr tcell.Screen, style tcell.Style) { | ||||||
| 	for _, char := range s { | 	for _, char := range s { | ||||||
| 		if x >= w { | 		if x >= w { | ||||||
| 			if y >= h { | 			if y >= h { | ||||||
| 				break; | 				break | ||||||
| 			} | 			} | ||||||
| 			x = 0 | 			x = 0 | ||||||
| 			y++ | 			y++ | ||||||
|  | @ -93,10 +92,10 @@ func drawMonth(m time.Month, x, y int) { | ||||||
| 	centeredText(months[m], x, y, monthWidth, wall, defStyle) | 	centeredText(months[m], x, y, monthWidth, wall, defStyle) | ||||||
| 
 | 
 | ||||||
| 	for i := 1; i <= 7; i++ { | 	for i := 1; i <= 7; i++ { | ||||||
| 		centeredText(weekdays[i % 7], x + (i - 1) * (dayWidth + smallGap), y + 1, dayWidth, wall, defStyle) | 		centeredText(weekdays[i%7], x+(i-1)*(dayWidth+smallGap), y+1, dayWidth, wall, defStyle) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	dayNum := date(selTime.Year(), m + 1, 0).Day() | 	dayNum := date(selTime.Year(), m+1, 0).Day() | ||||||
| 	for i := 1; i <= dayNum; i++ { | 	for i := 1; i <= dayNum; i++ { | ||||||
| 		weekday := int(date(selTime.Year(), m, i).Weekday()) | 		weekday := int(date(selTime.Year(), m, i).Weekday()) | ||||||
| 		style := defStyle | 		style := defStyle | ||||||
|  | @ -105,8 +104,8 @@ func drawMonth(m time.Month, x, y int) { | ||||||
| 		} | 		} | ||||||
| 		centeredText( | 		centeredText( | ||||||
| 			strconv.Itoa(i), | 			strconv.Itoa(i), | ||||||
| 			x + ((weekday - 1 + 7) % 7) * (dayWidth + smallGap), | 			x+((weekday-1+7)%7)*(dayWidth+smallGap), | ||||||
| 			y + 2, | 			y+2, | ||||||
| 			2, | 			2, | ||||||
| 			wall, | 			wall, | ||||||
| 			style) | 			style) | ||||||
|  | @ -119,7 +118,7 @@ func drawMonth(m time.Month, x, y int) { | ||||||
| func drawWall() { | func drawWall() { | ||||||
| 	wall.Clear() | 	wall.Clear() | ||||||
| 	w, h := wall.Size() | 	w, h := wall.Size() | ||||||
| 	if w < monthWidth + 2 * smallGap || h < monthHeight + 2 * smallGap + titleHeight { | 	if w < monthWidth+2*smallGap || h < monthHeight+2*smallGap+titleHeight { | ||||||
| 		wrappedText("Екран је премали за календар.", wall, defStyle) | 		wrappedText("Екран је премали за календар.", wall, defStyle) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  | @ -127,13 +126,13 @@ func drawWall() { | ||||||
| 	monthsHigh := (h - smallGap - titleHeight) / (monthHeight + smallGap) | 	monthsHigh := (h - smallGap - titleHeight) / (monthHeight + smallGap) | ||||||
| 	monthsDrawn := min(monthsHigh*monthsWide, 12) // TODO: izraziti 12 drugacije?? | 	monthsDrawn := min(monthsHigh*monthsWide, 12) // TODO: izraziti 12 drugacije?? | ||||||
| 
 | 
 | ||||||
| 	startingMonth := time.Month((int(selTime.Month()) - 1) / monthsDrawn * monthsDrawn + 1) | 	startingMonth := time.Month((int(selTime.Month())-1)/monthsDrawn*monthsDrawn + 1) | ||||||
| 	endingMonth := time.Month(min(12, int(startingMonth) + monthsDrawn - 1)) | 	endingMonth := time.Month(min(12, int(startingMonth)+monthsDrawn-1)) | ||||||
| 
 | 
 | ||||||
| 	centerVert := (w - monthsWide*monthWidth - (monthsWide-1)*largeGap) / 2 | 	centerVert := (w - monthsWide*monthWidth - (monthsWide-1)*largeGap) / 2 | ||||||
| 	for i, m := 0, startingMonth ; i < monthsHigh ; i++ { | 	for i, m := 0, startingMonth; i < monthsHigh; i++ { | ||||||
| 		for j := 0 ; j < monthsWide ; j++ { | 		for j := 0; j < monthsWide; j++ { | ||||||
| 			drawMonth(m, centerVert + j*(monthWidth+largeGap), titleHeight + smallGap + i*(monthHeight+smallGap)) | 			drawMonth(m, centerVert+j*(monthWidth+largeGap), titleHeight+smallGap+i*(monthHeight+smallGap)) | ||||||
| 			if m >= endingMonth { | 			if m >= endingMonth { | ||||||
| 				return | 				return | ||||||
| 			} | 			} | ||||||
|  | @ -160,7 +159,6 @@ func main() { | ||||||
| 	wall.Clear() | 	wall.Clear() | ||||||
| 	drawWall() | 	drawWall() | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 	quit := func() { | 	quit := func() { | ||||||
| 		wall.Fini() | 		wall.Fini() | ||||||
| 		os.Exit(0) | 		os.Exit(0) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Petar Kapriš
						Petar Kapriš