mirror of
				https://github.com/flynx/colors.js.git
				synced 2025-10-31 12:00:08 +00:00 
			
		
		
		
	[api] Make colors.setTheme sync call
This commit is contained in:
		
							parent
							
								
									e33dc81671
								
							
						
					
					
						commit
						891da6434c
					
				
							
								
								
									
										11
									
								
								colors.js
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								colors.js
									
									
									
									
									
								
							| @ -100,19 +100,14 @@ exports.addSequencer('zebra', function (letter, i, exploded) { | |||||||
|   return i % 2 === 0 ? letter : letter.inverse; |   return i % 2 === 0 ? letter : letter.inverse; | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| exports.setTheme = function (theme, cb) { | exports.setTheme = function (theme) { | ||||||
|   if(typeof cb !== 'function') { |  | ||||||
|     cb = function (err, result) { |  | ||||||
|       console.log(err); |  | ||||||
|     }; |  | ||||||
|   } |  | ||||||
|   if (typeof theme === 'string') { |   if (typeof theme === 'string') { | ||||||
|     try { |     try { | ||||||
|       exports.themes[theme] = require(theme); |       exports.themes[theme] = require(theme); | ||||||
|       applyTheme(exports.themes[theme]); |       applyTheme(exports.themes[theme]); | ||||||
|       cb(null, exports.themes[theme]); |       return exports.themes[theme]; | ||||||
|     } catch (err) { |     } catch (err) { | ||||||
|       return cb(err); |       return err; | ||||||
|     } |     } | ||||||
|   } else { |   } else { | ||||||
|     applyTheme(theme); |     applyTheme(theme); | ||||||
|  | |||||||
							
								
								
									
										10
									
								
								example.js
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								example.js
									
									
									
									
									
								
							| @ -67,11 +67,7 @@ console.log("this is a warning".warn); | |||||||
| console.log("this is an input".input); | console.log("this is an input".input); | ||||||
| 
 | 
 | ||||||
| // Load a theme from file
 | // Load a theme from file
 | ||||||
| colors.setTheme('./themes/winston-dark.js', function(err){ | colors.setTheme('./themes/winston-dark.js'); | ||||||
|   if (err) { | 
 | ||||||
|     return console.log('error loading theme '.error, err) | console.log("this is an input".input); | ||||||
|   } |  | ||||||
|   // outputs black text
 |  | ||||||
|   console.log("this is an input".input); |  | ||||||
| }); |  | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user